Question

In: Computer Science

use eclipse give me java codes Task III: Write a classCarInsurancePolicy The CarInsurancePolicy class will...

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.

Solutions

Expert Solution

//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


Related Solutions

Using Java preferably with Eclipse Task: Write a program that creates a class Apple and a...
Using Java preferably with Eclipse Task: Write a program that creates a class Apple and a tester to make sure the Apple class is crisp and delicious. Instructions: First create a class called Apple The class Apple DOES NOT HAVE a main method Some of the attributes of Apple are Type: A string that describes the apple.  It may only be of the following types:  Red Delicious  Golden Delicious  Gala  Granny Smith Weight: A decimal value representing...
This is Java class working on the eclipse. I include some of the codes just so...
This is Java class working on the eclipse. I include some of the codes just so you know what needed. create and work with interfaces you'll create the DepartmentConstants interface presented. In addition, you'll implement an interface named Displayable that's similar to the Printable interface Create the interfaces 1- Import the project named ch12-ex1_DisplayableTest and review the codes package murach.test; public interface Displayable {     String getDisplayText(); } 2 . Note that this code includes an interface named Displayable that...
IN JAVA ECLIPSE PLEASE The xxx_Student class A Student has a: – Name - the name...
IN JAVA ECLIPSE PLEASE The xxx_Student class A Student has a: – Name - the name consists of the First and Last name separated by a space. – Student Id – a whole number automatically assigned in the student class – Student id numbers start at 100. The numbers are assigned using a static variable in the Student class • Include all instance variables • Getters and setters for instance variables • A static variable used to assign the student...
write on eclipse java Write a program named lab5 that will play a game of Blackjack...
write on eclipse java Write a program named lab5 that will play a game of Blackjack between the user and the computer. Create a second class named Card with the following: Define the following private instance variables: cardValue (int) & cardSuite (String) Write a constructor with no parameters that will Set cardValue to a random number between 1 and 13 Generate a second random number between 0 and 3 and assign cardSuite a string based on its value (0 –...
Task #1 The if Statement, Comparing Strings, and Flags (JAVA using Eclipse IDE 14) Create the...
Task #1 The if Statement, Comparing Strings, and Flags (JAVA using Eclipse IDE 14) Create the file PizzaOrder.java. Prompt the user to input the type of pizza that they want to order. In the end, you should print out the final order and price. Here is a sample output. Welcome to May and Adam’s Pizzeria Enter your first name: Amy Pizza Size(inches)     Cost         10            $10.99         12            $12.99         14            $14.99         16            $16.99 What size pizza would you...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the following variables: an instance variable that describes the title - String an instance variable that describes the ISBN - String an instance variable that describes the publisher - String an instance variable that describes the price - double an instance variable that describes the year – integer Provide a toString() method that returns the information stored in the above variables. Create the getter and...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the following variables: an instance variable that describes the title - String an instance variable that describes the ISBN - String an instance variable that describes the publisher - String an instance variable that describes the price - double an instance variable that describes the year – integer Provide a toString() method that returns the information stored in the above variables. Create the getter and...
PLZ USE ECLIPSE JAVA and show output with explanation The object of this assignment is to...
PLZ USE ECLIPSE JAVA and show output with explanation The object of this assignment is to construct a mini-banking system that helps us manage banking data. Notice that you can copy and paste your code from previous assignments. This assignment asks you to allow read from/write to file, as well as search and sorting algorithm. The object of this assignment is to construct a mini-banking system that helps us manage banking data. This assignment asks you to allow read from/write...
(USE C ++ AND class STRING ONLY!!!! No java, No cstring and No vector) Write a...
(USE C ++ AND class STRING ONLY!!!! No java, No cstring and No vector) Write a program that can be used to train the user to use less sexist language by suggesting alternative versions of sentences given by the user. The program will ask for a sentence, read the sentence into a string variable, and replace all occurrences of masculine pronouns with genderneutral pronouns. For example, it will replace "he" with "she or he". Thus, the input sentence See an...
I need to write a java program (in eclipse) that will read my text file and...
I need to write a java program (in eclipse) that will read my text file and replace specific placeholders with information provided in a second text file. For this assignment I am given a text file and I must replace <N>, <A>, <G>, with the information in the second file. For example the information can be John 22 male, and the template will then be modified and saved into a new file or files (because there will be multiple entries...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT