object with a radius of 0. Display the results in a GUI interface immediately af
ID: 3698168 • Letter: O
Question
object with a radius of 0. Display the results in a GUI interface immediately after creating each object. Upload Circle.java, Sphere, java and testSphere.java Create a program that has an abstract class called Insurance with fields for the insurance company's name, policy number, and cost per month. Write get and set methods for all fields. Write a default constructor that sets the Insurance Company name to "Daffy Duck Insurance" sets the policy number to "11111," and the cost per month to $100.00. Include an abstract method called calcYearlyFee(). Create a subclass for Health Insurance that includes a prescription cost data field. Write a constructor for the Health Insurance that accepts the insurance company name, the policy number, the cost per month, and the prescription cost as arguments. Calculate the yearly fee based on the cost per month * 12 months and the prescription cost * 12 months. Write any other needed methods. Create a class for Car Insurance that includes a deductible data field. Write a constructor for the Car Insurance that accepts the insurance company name, the policy number, the cost per month, and the deductible as arguments. Calculate the yearly fee based on the cost per month * 12 months. Write any other needed methods. Write a program that creates objects of these two subclasses and displays the formation. Upload all the files. Using Password.java, revise it to be sure at least one lowercase letter and uppercase letter are part of the password entered by the user. Password.java when done.Explanation / Answer
Hello there ,
Please find below code and it's output.
/**
* Insurance class .
* @author dipal.prajapati
*
*/
public abstract class Insurance {
private String companyName;
private int policyNumber;
private double costPerMonth;
public Insurance() {
super();
this.companyName="Daffy Duck Insurance";
this.policyNumber=11111;
this.costPerMonth=100;
}
public Insurance(String companyName, int policyNumber, double costPerMonth) {
super();
this.companyName = companyName;
this.policyNumber = policyNumber;
this.costPerMonth = costPerMonth;
}
public String getCompanyName() {
return companyName;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
}
public int getPolicyNumber() {
return policyNumber;
}
public void setPolicyNumber(int policyNumber) {
this.policyNumber = policyNumber;
}
public double getCostPerMonth() {
return costPerMonth;
}
public void setCostPerMonth(double cost) {
this.costPerMonth = cost;
}
public abstract double calcYearlyFee();
}
====
/**
* It represents Health Insurance class.
* @author dipal.prajapati
*
*/
public class HealthInsurance extends Insurance {
private double prescriptionCost;
public HealthInsurance(String companyName, int policyNumber, double costPerMonth, double prescriptionCost) {
super(companyName, policyNumber, costPerMonth);
this.prescriptionCost = prescriptionCost;
}
public double getPrescriptionCost() {
return prescriptionCost;
}
public void setPrescriptionCost(double prescriptionCost) {
this.prescriptionCost = prescriptionCost;
}
@Override
public double calcYearlyFee() {
return ((getCostPerMonth() * 12) + (getPrescriptionCost() * 12));
}
@Override
public String toString() {
return "HealthInsurance [companyName=" + getCompanyName() + ", policyNumber=" + getPolicyNumber() + ", costPerMonth=" + getCostPerMonth() + ", prescriptionCost=" + getPrescriptionCost() + "]";
}
}
=====
/**
* It represents Car insurance class.
* @author dipal.prajapati
*
*/
public class CarInsurance extends Insurance {
private double deductibleCost;
public CarInsurance(String companyName, int policyNumber, double costPerMonth, double deductibleCost) {
super(companyName, policyNumber, costPerMonth);
this.deductibleCost = deductibleCost;
}
public double getDeductibleCost() {
return deductibleCost;
}
public void setDeductibleCost(double deductibleCost) {
this.deductibleCost = deductibleCost;
}
@Override
public double calcYearlyFee() {
return (getCostPerMonth() * 12);
}
@Override
public String toString() {
return "CarInsurance [companyName=" + getCompanyName() + ", policyNumber=" + getPolicyNumber() + ", costPerMonth=" + getCostPerMonth() + ", deductibleCost=" + getDeductibleCost() + "]";
}
}
=====
/**
* Driver Class
* @author dipal.prajapati
*
*/
public class InsuranceDriver {
public static void main(String args[]){
HealthInsurance healthInsurance=new HealthInsurance("XYZ Insurance", 23433, 100,40);
CarInsurance carInsurance=new CarInsurance("PQR Car Insurance", 45657, 150, 10);
System.out.println(healthInsurance.toString());
System.out.println(carInsurance.toString());
}
}
=====O/P===
HealthInsurance [companyName=XYZ Insurance, policyNumber=23433, costPerMonth=100.0, prescriptionCost=40.0]
CarInsurance [companyName=PQR Car Insurance, policyNumber=45657, costPerMonth=150.0, deductibleCost=10.0]
If you have any doubts , let me know.
Thanks.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.