Question

Please use Java to write the program The purpose of this lab is to practice using...

Please use Java to write the program

The purpose of this lab is to practice using inheritance and polymorphism. We need a set of
classes for an Insurance company. Insurance companies offer many different types of policies:
car, homeowners, flood, earthquake, health, etc. Insurance policies have a lot of data and
behavior in common. But they also have differences. You want to build each insurance policy
class so that you can reuse as much code as possible. Avoid duplicating code. You’ll save
time, have less code to write, and you’ll reduce the likelihood of bugs.

Task I: Write a class Customer
The Customer class will describe the properties and behavior representing one customer of the
insurance company.
1. The data members should include a name, and the state the customer lives in
2. Override the equals() function. You may consider two customers to be equal if they have
the same name and live in the same state (See the Object class API if you need to know what
the function prototype looks like)
3. Add any additional methods you need to complete the rest of the lab
Task II: Write a class InsurancePolicy
The InsurancePolicy class will describe the properties and behavior that all insurance policies
have in common.
4. The data members should include a customer name, a policy number (you can use an
integer), and a policy expiration date (use LocalDate)
5. Write a constructor that takes two parameters -- the Customer name and the policy number .
Your class should not have a default constructor.
6. Write a set function that a user will use to modify the policy expiration date.
7. Write get functions for your data members
8. Write a function isExpired() that returns true if the policy has expired, false otherwise.
You can determine this by comparing the expiration date against the current date.
9. Override the toString() function (See the Object class API if you need to know what the
function prototype looks like)
10. Override the equals() function. You may consider two policies to be equal if they have the
same policy number (See the Object class API if you need to know what the function
prototype looks like)

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.
Task IV: Write tests for the Customer class and the CarInsurance classes
These tests should be put in a separate package.
1. Make sure that you include tests for the equals() method of Customer and the calculateCost()
method of CarInsurance.
Task V: Write a class HomeInsurancePolicy
The HomeInsurancePolicy class will describe an insurance policy for a home.
2. The data members should include all the data members of an Insurance Policy, but also the
estimated cost to rebuild the home, and the estimated property value
3. Write a constructor that takes two parameters -- the customer and the policy number .
4. Write the necessary get/set functions for your class.
5. Write a function calculateCost() that will return the cost of the home insurance policy . The
cost of the policy should be 0.5% of the sum of rebuild cost and the property value. Add a
5% premium to the policy cost if the customer lives in a “high cost” state of California or
New York.
Task VI: Write a class FloodInsurancePolicy

Flood insurance is a special type of homeowners insurance. Damage caused by floods is
typically not covered by a home insurance policy. To be covered in case of a flood, homeowners
need to buy a flood insurance policy.
1. The data members should include all the data members of HomeInsurancePolicy (because
this is a special type of homeowner’s insurance), but also an integer value between 1 and 99
representing the flood risk (a value of 1 will represent that the probability of a flood in the
home’s area is very low, a value of 99 will represent that the home is in an area that
frequently floods.
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 flood insurance policy . The
cost of the policy should be the flood risk number divided by 100 and then multiplied by the
home’s rebuild cost. Add a 7% premium to the policy cost if the customer lives in a “high
cost” state of California or New York.
Task VII: A Customer should have an array of insurance policies
It is common for insurance customers to hold multiple policies with the same insurance company.
We need our Customer class to reflect this. Modify your Customer class so that it has an array
of insurance policies. Also add a function addPolicy() that will add an insurance policy to the
array. It should be an error to add an insurance policy that has a name different from the name
in the customer object. In other words, if you are adding an insurance policy to a customer, then
the insurance policy should have a reference to the same customer name. If they are not, print
an error message and do not add the policy to the array.
Task VIII: Write a test program (class)
1. This class should be in a different package than your insurance classes
2. This class will include your main() function and will be used to test the insurance classes.
You do not need to write an interactive user interface to test your classes. You’ll hardcode
some data (object instantiations), call the various functions and print some results.
3. This next step will help you learn how to put multiple objects together to build more complex
data structures. Write a function that is not main() (but is called by main!) that does the
following testing:
• instantiate a couple of Customer objects
• instantiate a few different types of insurance policies and assign them to a customer
using the customer’s addPolicy() method
4. Write a function computeInsuranceBill() that takes a Customer as a parameter and returns the
cost of all the Customer’s insurance policies. This is the amount the customer will be billed
to renew the policies.
5. Write a function policiesExpiring() that takes a Customer as a parameter and returns an
ArrayList containing the policies that have either expired or that will expire during the currentmonth. Thus if the current month is June 2019, any policy expiring in June 2019 would be
included in the ArrayList that is returned.
6. Although you should thoroughly test all functions and classes you write, you only need to
turn in a program that performs the tests described in the items above. ONLY
turn in the tests described above. Remove your additional testing code BEFORE handing in
the lab. The code you hand in should be neat, easily readable and only perform the testing
described above – avoid messy code and add a few comments to describe the tests you are
performing.
7. Correct functionality is only part of the grade. Readability, neat and well written code will
also be part of the grade. Use good variable names, and good formatting so that your code
is easy to read and understand.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//Customer.java

package com.study.abc;

public class Customer {

   private String name;
   private String state;
   private InsurancePolicy[] policyArray;
   private static int policyCount = 0;
  
   public InsurancePolicy[] getPolicyArray() {
       return policyArray;
   }

   public int getPolicyCount() {
       return policyCount;
   }

   public void setPolicyArray(InsurancePolicy[] policyArray) {
       this.policyArray = policyArray;
   }

   public String getName() {
       return name;
   }
  
   public void setName(String name) {
       this.name = name;
   }
  
   public String getState() {
       return state;
   }
  
   public void setState(String state) {
       this.state = state;
   }
  
   public void addPolicy(InsurancePolicy p) {
      
       if(!this.name.equalsIgnoreCase(p.getName())) {
          
           System.out.println("Policy does not belong to customer : " + getName());
          
       } else {
           policyArray[policyCount++] = p;          
       }
   }

   @Override
   public boolean equals(Object o) {
       if(o.getClass() == Customer.class)
       {
           Customer c = (Customer)o;
           if(this.name.equalsIgnoreCase(c.name) && this.state.equalsIgnoreCase(c.state))
               return true;
       }
      
       return false;
      
   }
}

//InsuracnePolicy.java

package com.study.abc;

import java.time.LocalDateTime;

public class InsurancePolicy extends Customer {

   //class attributes  
   private int policyNumber;
   private LocalDateTime expiryDate;
  
   //User defined constructor
   public InsurancePolicy(String cName, int pNumber) {
       this.setCustomerName(cName);
       this.policyNumber = pNumber;
   }
  
   public boolean IsExpired() {
       return this.expiryDate.isAfter(LocalDateTime.now());
   }
  
   public void setCustomerName(String customerName) {
       this.setCustomerName(customerName);
   }
   public int getPolicyNumber() {
       return policyNumber;
   }
   public void setPolicyNumber(int policyNumber) {
       this.policyNumber = policyNumber;
   }
   public LocalDateTime getExpiryDate() {
       return expiryDate;
   }
   public void setExpiryDate(LocalDateTime expiryDate) {
       this.expiryDate = expiryDate;
   }
  
   @Override
   public String toString() {
       return "Insurance Policy Holder Name : " + getCustomerName() + "\nPolicy Number : " + getPolicyNumber() + "\nPolicy Expiry Date: " + getExpiryDate().toString();
   }
  
   @Override
   public boolean equals(Object o) {
      
       if(o.getClass() == InsurancePolicy.class)
       {
           InsurancePolicy policy = (InsurancePolicy)o;
           if(this.policyNumber == policy.policyNumber)
               return true;
       }
      
       return false;
      
   }
}

//CarInsurancepolicy.java

package com.study.abc;

public class CarInsurancePolicy extends InsurancePolicy{

   private DriverLicense licenseNumber;
   private Car customerCar;
  
   public CarInsurancePolicy(String cName, int pNumber) {
       super(cName, pNumber);
   }

   public DriverLicense getLicenseNumber() {
       return licenseNumber;
   }

   public void setLicenseNumber(DriverLicense licenseNumber) {
       this.licenseNumber = licenseNumber;
   }

   public Car getCustomerCar() {
       return customerCar;
   }

   public void setCustomerCar(Car customerCar) {
       this.customerCar = customerCar;
   }
  
   public double calculateCost() {
      
       if(licenseNumber.getStatus().equals("good")) {
           double carPolicyCost = (customerCar.getEstimatedValue() * 5)/100;
           if(getState().equalsIgnoreCase("NY") || getState().equalsIgnoreCase("CA"))
               carPolicyCost += (carPolicyCost)*10/100;
          
           return carPolicyCost;
       }
       else {
           double carPolicyCost = (customerCar.getEstimatedValue() * 8)/100;
           if(getState().equalsIgnoreCase("NY") || getState().equalsIgnoreCase("CA"))
               carPolicyCost += (carPolicyCost)*10/100;
          
           return carPolicyCost;
       }
          
   }

}

//Car.java

package com.study.abc;

public class Car {

   private String make;
   private String model;
   private double 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;
   }
  
}

//DrivingLicens.java

package com.study.abc;

public class DriverLicense {

   private String licenseNumber;
   private String status;
  
   public String getLicenseNumber() {
       return licenseNumber;
   }
   public void setLicenseNumber(String licenseNumber) {
       this.licenseNumber = licenseNumber;
   }
   public String getStatus() {
       return status;
   }
   public void setStatus(String status) {
       this.status = status;
   }
  
}

//HomeInsurancePolicy.java

package com.study.abc;

public class HomeInsurancePolicy extends InsurancePolicy {

   private double estimatedRebuildCost;
   private double estimatedPropertyValue;

   public double getEstimatedRebuildCost() {
       return estimatedRebuildCost;
   }

   public void setEstimatedRebuildCost(double estimatedRebuildCost) {
       this.estimatedRebuildCost = estimatedRebuildCost;
   }

   public double getEstimatedPropertyValue() {
       return estimatedPropertyValue;
   }

   public void setEstimatedPropertyValue(double estimatedPropertyValue) {
       this.estimatedPropertyValue = estimatedPropertyValue;
   }

   public HomeInsurancePolicy(String cName, int pNumber) {
       super(cName, pNumber);
   }

   public double calculateCost() {

       double homePolicyCost = (getEstimatedPropertyValue() + getEstimatedRebuildCost()) * 0.5 / 100;
       if (getState().equalsIgnoreCase("NY") || getState().equalsIgnoreCase("CA"))
           homePolicyCost += (homePolicyCost) * 5 / 100;

       return homePolicyCost;
   }
}

//FloodInsurancePolicy.java

package com.study.abc;

public class FloodInsurancePolicy extends HomeInsurancePolicy{

   private int floodRisk;
  
   public int getFloodRisk() {
       return floodRisk;
   }

   public void setFloodRisk(int floodRisk) {
       this.floodRisk = floodRisk;
   }

   public FloodInsurancePolicy(String cName, int pNumber) {
       super(cName, pNumber);
   }
  
   public double calculateCost() {

       double floodPolicyCost = (getFloodRisk()/100)*getEstimatedRebuildCost();
       if (getState().equalsIgnoreCase("NY") || getState().equalsIgnoreCase("CA"))
           floodPolicyCost += (floodPolicyCost) * 7 / 100;

       return floodPolicyCost;
   }

}

//testProgram.java

package com.study.abc.test;

import com.study.abc.Car;
import com.study.abc.CarInsurancePolicy;
import com.study.abc.Customer;
import com.study.abc.DriverLicense;
import com.study.abc.InsurancePolicy;

public class testProgram {

   public static void main(String[] args) {
      
       Customer c = CreateUserData();
       computeInsuranceBill(c);
   }
  
   private static void computeInsuranceBill(Customer c) {

       InsurancePolicy [] p = c.getPolicyArray();
       if(p[0].getClass() == CarInsurancePolicy.class)
       {
           CarInsurancePolicy cp = (CarInsurancePolicy)p[0];
           System.out.println("Cost of policy : "+ cp.calculateCost());
       }
      
   }

   public static Customer CreateUserData() {
      
       Customer c1 = new Customer();
       c1.setName("mark");
       c1.setState("NY");
      
       Customer c2 = new Customer();
       c2.setName("steve");
       c2.setState("CA");
      
       CarInsurancePolicy car = new CarInsurancePolicy("mark", 123);
      
       Car c = new Car();
       c.setMake("Honda");
       c.setModel("Benz");
       c.setEstimatedValue(10002);
      
       DriverLicense dl = new DriverLicense();
       dl.setLicenseNumber("KA02123324");
       dl.setStatus("good");
       car.setLicenseNumber(dl);
      
       c1.addPolicy(car);
      
       return c1;
   }
}

Add a comment
Know the answer?
Add Answer to:
Please use Java to write the program The purpose of this lab is to practice using...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ IMPORTANT: Write a driver program (PackageDriver) that creates objects of each type of Package as...

    C++ IMPORTANT: Write a driver program (PackageDriver) that creates objects of each type of Package as pointers to a Package and cout the objects. Write a driver program (PackageDriver) that creates objects of each type of Package as pointers to a Package and cout the objects. Write a driver program (PackageDriver) that creates objects of each type of Package as pointers to a Package and cout the objects. Package-delivery services, such as FedEx®, DHL® and UPS®, offer a number of...

  • C++ Program 1a. Purpose Practice the creation and use of a Class 1b. Procedure Write a...

    C++ Program 1a. Purpose Practice the creation and use of a Class 1b. Procedure Write a class named Car that has the following member variables: year. An int that holds the car’s model year. make. A string object that holds the make of the car. speed. An int that holds the car’s current speed. In addition, the class should have the following member functions. Constructor. The constructor should accept the car’s year and make as arguments and assign these values...

  • in java please Purpose: To practice designing a class that can be used in many applications....

    in java please Purpose: To practice designing a class that can be used in many applications. To write and implement a thorough test plan. You are NOT to use any of the Java API date classes (Gregorian calendar, Date…) except for the constructor method to set the date fields to the current data. Write a class to hold data and perform operations on dates. Ie: January 2, 2019   or 3/15/2018 You must include a toString( ), an equals( ) and...

  • Write java program The purpose of this assignment is to practice OOP with Array and Arraylist,...

    Write java program The purpose of this assignment is to practice OOP with Array and Arraylist, Class design, Interfaces and Polymorphism. Create a NetBeans project named HW3_Yourld. Develop classes for the required solutions. Important: Apply good programming practices Use meaningful variable and constant names. Provide comment describing your program purpose and major steps of your solution. Show your name, university id and section number as a comment at the start of each class. Submit to Moodle a compressed folder of...

  • Java programming The purpose of this problem is to practice using a generic Urn class. NOTE:...

    Java programming The purpose of this problem is to practice using a generic Urn class. NOTE: Refer to the code for the ArrayStack class from Chapter 12. Use that code as a starting point to create the Urn class, modifying it to remove the methods in the ArrayStack class (push, pop, etc) then add the methods described below. Also change the variable names to reflect the new class. For example the array name should NOT be stack, instead it should...

  • Please help with this assignment. Thanks. 1. Write a C++ program containing a class Invoice and...

    Please help with this assignment. Thanks. 1. Write a C++ program containing a class Invoice and a driver program called invoiceDriver.cpp. The class Invoice is used in a hardware store to represent an invoice for an item sold at the store. An invoice class should include the following: A part number of type string A part description of type string A quantity of the item being purchased of type int A price per item of type int A class constructor...

  • Write a program

    1. Write a program which have a class named as “Student”, while the data members of the class are,a. char name[10],b. int age;c. string color;d. string gender;e. double cgpa;and the member function “print()”,  is just to display these information.1. You need to create 3 objects of the “Student” class.2. Initialize one object by the default constructor having some static values.3. Initialize the second object by the parameterized constructor, while you need to pass values for initialization.4. Initialize the third object...

  • (C++ Program) 1. Write a program to allow user enter an array of structures, with each...

    (C++ Program) 1. Write a program to allow user enter an array of structures, with each structure containing the firstname, lastname and the written test score of a driver. - Your program should use a DYNAMIC array to make sure user has enough storage to enter the data. - Once all the data being entered, you need to design a function to sort the data in descending order based on the test score. - Another function should be designed to...

  • write in java code. oop. i dont have its written code. i have its output in...

    write in java code. oop. i dont have its written code. i have its output in the thrid picture and how the inheritance works with the second picture. just need it in full written code and uni class will be. jus need you to write the whole code for me as its an extra question which i need for my preparation of my exam. add as you but it must be correct and similar to the question Inheritance Do the...

  • Sorting Threads Assignment Overview Write a multithreaded sorting program in Java which uses the ...

    Sorting Threads Assignment Overview Write a multithreaded sorting program in Java which uses the merge sort algorithm. The basic steps of merge sort are: 1) divide a collection of items into two lists of equal size, 2) use merge sort to separately sort each of the two lists, and 3) combine the two sorted lists into one sorted list. Of course, if the collection of items is just asingle item then merge sort doesn’t need to perform the three steps,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT