Question
TO DO in JAVA: Finish the HealthInsurance and LifeInsurance classes. Uncomment my instances in main() of TrackInsurance. The red Xs should be gone. package itp120mod6;
TO DO in JAVA: Finish the HealthInsurance and LifeInsurance classes. Uncomment my instances in main() of TrackInsurance. The red Xs should be gone.
package itp120mod6;
Health Insurance (below)
// "Extends" means inherit all the methods and fields from Insurance
public class HealthInsurance extends Insurance {
// create a new field called numDependents which is an integer
int numDependents;
// creat a full constructor for a new object. Make certain it sets the rate
public HealthInsurance (Customer cust, int dependents)
{
// you code the body
numDependents = 2;
}
// full constructor if read from a file
public HealthInsurance (Customer cust, int polNum, double yrRate, int numD)
{
super(cust,polNum,yrRate);
numDependents = numD;
}
// empty constuctor
public HealthInsurance ()
{
}
// required to make a complete class since we inherited from Insurance that had this method abstract
public void calcRate()
{
yearlyRate = 500 * numDependents;
}
// toString method. First call the one from the super class (Insurance) to write those fields
// and add on the new fields for this class
// we override the toString method from the Insurance class
public String toString ()
{
// you put the code here
}
// generate getters and setters
}
----------------------------------------------------------------------------------------------------------------
Life Insurance (below)
package itp120mod6;
// "extends" means inherits methods and fields from the Insurance class
public class LifeInsurance extends Insurance
{
// declare two new fields added - the amount of insurance they want (amount - an integer) and their age (age - an integer )
// full constructor. Let super (Insurance) set any fields that really came from there.
// Make certain to also set the rate
public LifeInsurance (Customer cust,int amtIns, int custAge)
{
// you code the body
}
// empty constructor
public LifeInsurance ()
{
}
// full constructor if reading from a file
public LifeInsurance (Customer cust, int polNum, double yrRate, int amtIns, int custAge)
{
// you code this
}
// required to write this if this class is to be a real class - fulfills the abstract requirements
public void calcRate()
{
if (age>40)
yearlyRate = amount*.005*2;
else
yearlyRate = amount*.005;
}
// to String. Let the Insurance class print out its fields and let this class print out new fields
// we override the toString method from the Insurance class
public String toString ()
{
// you code the body
}
// generate the getters and setters
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started