Question: Testing Code import java.util.*; public class PolicyTester { public static void main(String args[]) { System.out.println(new Policy(320)); DepreciatingPolicy p1 = new DepreciatingPolicy(500.1f, 0.1f); System.out.println(p1); p1.depreciate(); System.out.println(p1);

![main(String args[]) { System.out.println(new Policy(320)); DepreciatingPolicy p1 = new DepreciatingPolicy(500.1f, 0.1f); System.out.println(p1);](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f025979f575_29466f02596ec341.jpg)
Testing Code
import java.util.*;
public class PolicyTester {
public static void main(String args[]) {
System.out.println(new Policy(320));
DepreciatingPolicy p1 = new DepreciatingPolicy(500.1f, 0.1f);
System.out.println(p1);
p1.depreciate();
System.out.println(p1);
System.out.println(new ExpiringPolicy(1000));
Date expDate = new GregorianCalendar(2021, 0, 2, 23, 59).getTime();
ExpiringPolicy p2 = new ExpiringPolicy(2000, expDate);
System.out.println(p2);
System.out.println(p2.isExpired());
expDate = new GregorianCalendar(2013, 3, 1, 23, 59).getTime();
ExpiringPolicy p3 = new ExpiringPolicy(2000, expDate);
System.out.println(p3);
System.out.println(p3.isExpired());
}
}
Expected output(date on line 4 will be different)
Policy: 0001 amount: $320.00
DepreciatingPolicy: 0002 amount: $500.10 rate: 10.0%
DepreciatingPolicy: 0002 amount: $450.09 rate: 10.0%
ExpiringPolicy: 0003 amount: $1000.00 expires: May 16, 2018 (01:18PM)
ExpiringPolicy: 0004 amount: $2000.00 expires: January 02, 2021 (11:59PM)
false
ExpiringPolicy: 0005 amount: $2000.00 expired on: April 01, 2013 (11:59PM)
true
(1) Policy Classes We will be creating this class hierarchy: To begin, copy the code from the following Policy class Object Policy public class Poliey private static int NEXT POLICY NUMBER = 1; DepreciatingPolicyExpiringPolicy private int policyNumber protected float anount; public Policy (float ant) amount amt ; policy tum bor NEXT POLICY NUMBER++; public int getPolicyNumbero return policyNumber: public float getAmounto return amounti public String tostring) return String-format ("Policy: %04d amount: %1.2f", policyNumber, amount); public boolean isExpired) t return false: Now define a DepreciatingPolicy class as a subclass of Policy which has the following a private instance variable called rate of type float which represents the rate at which the policy depreciates each time a claim is made. For example, a rate of 0.10 means that the value of the policy (ie, the amount) depreciates 10% each time a claim is made (we will discuss the making of claims in the next section). . e a public constructor which takes a float representing the amount and another float representing the rate. This constructor MUST make full/proper use of inheritance a public get method for the rate a toString) method that returns a String with the following example format: DepreciatingPolicy: 0001 amount $320.00 rate: 10.0% You MUST make use of inheritance by calling the toString) from the superclass. Also, the rate must be properly formatted
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
