Question: Java Please only do the UseInsurance with an ArrayList (Write an application named UseInsurance that prompts the user for the type of insurance to be

Java

Please only do the UseInsurance with an ArrayList (Write an application named UseInsurance that prompts the user for the type of insurance to be displayed, and then create the appropriate object. Use ArrayList to create array of Insurance objects and load all the different insurance objects into the array. Test your program thoroughly to ensure your design works properly. Save the files as Life.java, Health.java, Insurance.java, and UseInsurance.java.) Create the UML diagram.

The whole program:

Using the concepts above, write an application named UseInsurance that uses an abstract Insurance class and Health and Life subclasses to display different types of insurance policies and the cost per month. The Insurance class contains a String representing the type of insurance and a double that holds the monthly price. The Insurance class constructor requires a String argument indicating the type of insurance, but the Life and Health class constructors require no arguments. The Insurance class contains a get method for each field; it also contains two abstract methods named setCost() and display(). The Life class setCost() method sets the monthly fee to $36, and the Health class sets the monthly fee to $196.

Write an application named UseInsurance that prompts the user for the type of insurance to be displayed, and then create the appropriate object. Use ArrayList to create array of Insurance objects and load all the different insurance objects into the array. Test your program thoroughly to ensure your design works properly. Save the files as Life.java, Health.java, Insurance.java, and UseInsurance.java.

===============================

Code for Insurance.java

===============================

public abstract class Insurance {

public String insuranceType; public double monthlyPrice;

public Insurance(String insuranceType) { this.insuranceType = insuranceType; }

public String getInsuranceType() { return insuranceType; }

public double getMonthlyPrice() { return monthlyPrice; } public abstract void setCost(); public abstract void display(); }

================================

Code for Life.java

==================================

public class Life extends Insurance {

Life() { super("Life"); } public void setCost() { monthlyPrice = 36; }

public void display() {

System.out.println("Insurance Type :"+getInsuranceType()); System.out.println("Monthly Price :$"+getMonthlyPrice());

}

}

==================================

Code for Health.java

===================================

public class Health extends Insurance{

Health() { super("Health"); } public void setCost() { monthlyPrice = 196; }

public void display() {

System.out.println("Insurance Type :"+getInsuranceType()); System.out.println("Monthly Price :$"+getMonthlyPrice());

}

}

========================================

Class for UseInsurance.java

==========================================

import java.util.Scanner;

public class UseInsurance {

public static void main(String[] args) {

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!