In: Computer Science
use eclipse give me java codes Task III: Write a class CarInsurancePolicy The CarInsurancePolicy class will describe an insurance policy for a car. 1. The data members should include all the data members of an Insurance Policy, but also the driver’s license number of the customer, whether or not the driver is considered a “good” driver (as defined by state law) , and the car being insured (this should be a reference to a Car object -- write a separate Car class for this that includes the car’s make (e.g., “Honda” or “Ford”), model (e.g. “Accord” or “Fusion”), and estimated value. 2. Write a constructor that takes two parameters -- the customer and the policy number . 3. Write the necessary get/set functions for your class. 4. Write a function calculateCost() that will return the cost of the car insurance policy . The cost of the policy should be computed as follows: (a) 5% of the estimated car value if the driver is rated as a “good” driver, 8% of the estimated car value if the driver is not rated as a “good” driver. (b) The cost should then be adjusted based on where the customer lives. If the customer lives in one of the high cost states of California (“CA”) or New York (“NY”), add a 10% premium to the policy cost.
//Car.java
public class Car {
private String make;
private String model;
private double estimatedValue;
public Car(String make, String model, double
estimatedValue) {
this.make = make;
this.model = model;
this.estimatedValue =
estimatedValue;
}
public String getMake() {
return make;
}
public void setMake(String make) {
this.make = make;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public double getEstimatedValue() {
return estimatedValue;
}
public void setEstimatedValue(double
estimatedValue) {
this.estimatedValue =
estimatedValue;
}
@Override
public String toString() {
return "Make:" + make + "\n Model:"
+ model + "\nEstimated Value:"
+ estimatedValue;
}
}
_______________________________
// CarInsurancePolicy.java
public class CarInsurancePolicy {
private String licenceNumber;
private boolean isGood;
private Car car;
public CarInsurancePolicy(String licenceNumber,
boolean isGood, Car car) {
this.licenceNumber =
licenceNumber;
this.isGood = isGood;
this.car = car;
}
public String getLicenceNumber() {
return licenceNumber;
}
public void setLicenceNumber(String licenceNumber)
{
this.licenceNumber =
licenceNumber;
}
public boolean isGood() {
return isGood;
}
public void setGood(boolean isGood) {
this.isGood = isGood;
}
public Car getCar() {
return car;
}
public void setCar(Car car) {
this.car = car;
}
public double calculateCost() {
double cost = 0;
if (isGood) {
return 0.05 *
car.getEstimatedValue();
} else {
return 0.08 *
car.getEstimatedValue();
}
}
@Override
public String toString() {
return "Licence Number:" +
licenceNumber
+ "\nIs Good=" + isGood + "\ncar:" + car;
}
}
________________________________
// Test.java
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
String state;
/*
* Creating an Scanner class object
which is used to get the inputs
* entered by the user
*/
Scanner sc = new
Scanner(System.in);
// Getting the input entered by
the user
System.out.print("Enter Driver
Licence Number :");
String licenceNum =
sc.next();
System.out.print("Is Driver is Good
? ");
boolean isGood =
sc.nextBoolean();
System.out.print("Enter Car make
:");
String make = sc.next();
System.out.print("Enter Car model
:");
String model = sc.next();
System.out.print("Enter Car value
:");
double estimatedVal =
sc.nextDouble();
System.out.print("Enter State of
Customer lives in :");
state = sc.next();
Car c = new Car(make, model,
estimatedVal);
CarInsurancePolicy cip = new
CarInsurancePolicy(licenceNum, isGood, c);
double costOfPolicy =
cip.calculateCost();
if (state.equalsIgnoreCase("CA") ||
state.equalsIgnoreCase("NY")) {
costOfPolicy +=
0.10 * cip.calculateCost() + cip.calculateCost();
}
System.out.println(cip);
System.out.println("Cost of
Insurance Policy :$" + costOfPolicy);
}
}
_______________________________
Output:
Enter Driver Licence Number :DF4554
Is Driver is Good ? true
Enter Car make :Honda
Enter Car model :Accord
Enter Car value :780000
Enter State of Customer lives in :CA
Licence Number:DF4554
Is Good=true
car:Make:Honda
Model:Accord
Estimated Value:780000.0
Cost of Insurance Policy :$81900.0