Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here is the code for the follwing Policy, Expiring Policy(inherits from policy), and Depreciating Policy(inherits from policy) public class Policy { private static int NEXT_POLICY_NUMBER

image text in transcribedimage text in transcribedimage text in transcribed

Here is the code for the follwing Policy, Expiring Policy(inherits from policy), and Depreciating Policy(inherits from policy)

public class Policy { private static int NEXT_POLICY_NUMBER = 1; public int policyNumber; protected float amount; public Policy(float amt) { amount = amt; policyNumber = NEXT_POLICY_NUMBER++; } public int getPolicyNumber() { return policyNumber; } public float getAmount() { return amount; } public String toString() { return String.format("Policy: %04d amount: $%1.2f", policyNumber, amount); } public boolean isExpired() { return false; } } 
public class DepreciatingPolicy extends Policy { private float rate; public DepreciatingPolicy(float a, float r){ super(a); this.rate = r; } public float getRate(){ return rate; } @Override public String toString(){ return "Expiring Policy: 000" + getPolicyNumber() + " amount: $" + getAmount() + " rate: " + getRate() * 100f + "%"; } public boolean isExpired(){ if(getAmount() == 0){ return true; } else{ return false; } } public void depreciate(){ float amountTakeaway; amountTakeaway = amount * rate; amount -= amountTakeaway; } } 
import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class ExpiringPolicy extends Policy { private Date expiryDate; public ExpiringPolicy(float a, Date d) { super(a); expiryDate = d; } public ExpiringPolicy(float a) { super(a); GregorianCalendar aCalendar = new GregorianCalendar(); aCalendar.add(Calendar.YEAR, 1); expiryDate = aCalendar.getTime(); } public Date getExpiryDate() { return expiryDate; } public String toString() { return "Expiring Policy: " + getPolicyNumber() + " amount: $" + amount + " expired on: " + getExpiryDate(); } public boolean isExpired(){ Date x = new Date(); if(x.after(this.expiryDate)){ return true; } else if(x.before(this.expiryDate)){ return false; } else{ return false; } } } 

Completion == Thumbs up :)

(2) The Clients Object We will now define the following hierarchy: To begin, copy the code from the following Client class import java.util.*; public abstract class Client Client IndividualClient CompanyClient private static final int MAX POLICIES PER CLIENT10 private static int NEXTCLIENTID = 1; - - private String private int protected Policy[] protected int name id policies; numPolicies; public Client (String n) l name n ; id-NEXT CLIENT ID++ policiesnew Policy [MAX POLICIES PER CLIENT] numPolicies 0; public String getName) return name; public int getId) return id; public Policy[] getPolicies (return policies: public int getNumPolicies ) return numPolicies; public String toString) [ return string. forma t ("Client : %06d amount: %s", id, name); 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

7. List behaviors to improve effective leadership in meetings

Answered: 1 week ago

Question

6. Explain the six-step group decision process

Answered: 1 week ago