Question
Create the following in the Client class: a public method called totalCoverage() which returns a float containing the total amount of coverage of all the
Create the following in the Client class: a public method called totalCoverage() which returns a float containing the total amount of coverage of all the client's policies. a public method called addPolicy(Policy p) which adds the given Policy to the array of policies, provided that the limit has not been reached ... and returns the Policy object, or null if not added. a public method called openPolicyFor(float amt) which creates a new Policy for the amount specified in the parameter and adds it to the client using (and returning the result from) the addPolicy() method a public method called openPolicyFor(float amt, float rate) which creates a new DepreciatingPolicy for the amount and rate specified in the parameters and adds it to the client using (and returning the result from) the addPolicy() method. a public method called openPolicyFor(float amt, Date expire) which creates a new ExpiringPolicy for the amount and expiry date specified in the parameters and adds it to the client using (and returning the result from) the addPolicy() method above. a public method called getPolicy(int polNum) which examines all Policy objects in policies. If one is found whose policyNumber matches the input parameter, then it should be returned by the method. Otherwise null is returned. a public method called cancelPolicy(int polNum) which removes the police from the client's list with the given policy number, if found. It should return true if the policy was found, otherwise it should return false. When a policy is removed from the array, the empty location in the array should be replaced by the last policy in the array. a public abstract method called makeClaim(int polNum) that returns a float. Now create the two subclasses of Client, one called IndividualClient and the other called CompanyClient. Try compiling them. Notice that your test code will not compile. That's because subclasses DO NOT inherit constructors and java requires a constructor to be available. Do the following: Create a constructor (taking a single String argument) for each of these subclasses that calls the one in Client. Go back and alter your toString() method in Client class so that the proper client type is displayed. For example: CompanyClient 0001: Bob B. Pins To do this, you will want to figure out how to get the name of the class as a String. (hint: type this. and then let IntelliJ show a list of available methods. You need to find out what class you have and then find out the name of the class). Implement the makeClaim(int polNum) method in the IndividualClient class. If the policy with that number is not found or has expired, then nothing is to be done, just return 0. IndividualClients are allowed to make only 1 claim per regular Policy but DepreciatingPolicys and ExpiringPolicys can have multiple claims. So, you should cancel a regular policy after a claim is made on it. If the claim is being made for a DepreciatingPolicy, then you must make sure to depreciate the policy. This method should return the amount of the policy (amount after depreciating in the case of DepreciatingPolicys) if the claim was made ok, otherwise 0 is returned. In the Policy class, implement a method called handleClaim() that returns the amount of the policy. In the DepreciatingPolicy class, implement handleClaim() so that it returns the amount of the policy but also depreciates the policy. Note that the amount returned is the amount of the policy before it was depreciated. In the ExpiringPolicy class, implement handleClaim() so that it returns the amount of the policy as long as the policy has not yet expired, otherwise it returns 0. In the CompanyClient class, implement the makeClaim(int polNum) method so that it first checks to make sure the policy is one belonging to this client and then uses the double-dispatching technique by calling the handleClaim() method. You MUST NOT use any IF statements to determine the policy type ... that's would undo the advantages of double-dispatching. Note that CompanyClients DO NOT have their policy removed afterwards, and so you should make use of the getPolicy() method. If no policy is found with the given polNum, return 0; ____________________________________________________________________________________________ (3) Testing Now test what you have done with the following program: import java.util.GregorianCalendar; public class ClientTester { public static void main(String args[]) { // Create an individual client, open some policies and then make some claims IndividualClient ic = new IndividualClient("Bob B. Pins"); ic.openPolicyFor(100); ic.openPolicyFor(200, 0.10f); ic.openPolicyFor(300, new GregorianCalendar(2020, 0, 2, 23, 59).getTime()); ic.openPolicyFor(400, new GregorianCalendar(2009, 5, 4, 12, 00).getTime()); Policy p = new Policy(500); System.out.println("Here are the Individual Client's policies:"); for (int i=0; i
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