Modify HomeOwnersclasses so that they meet the revised requirements as shown in
ID: 3712275 • Letter: M
Question
Modify HomeOwnersclasses so that they meet the revised requirements as shown in the UML class diagrams.
Attributes private exposureRate: double Homeowners subclass of Policy Notes Current exposure rate for Homeowners policies is 0.0025 (or 0.2596). This is a constant value set directly in the set method. No data will be passed into the constructor for this value. private propAddress: String private propType: int private structure: int Legal address of insured property Numeric code describing property type: 1 - single family dwelling 2-townhouse, attached 3-townhouse, detached 4 - condominium If the offered value is not within range, default to a value of 1. Structural coverage limit, stated in thousands of dollars. Acceptable values are greater than 0 and no more than 10,000,000. If the offered value is not within range, throw an exception & do not create the Homeowners object. Contents limits, stated in thousands of dollars. Acceptable values are greater than 0 and not more than 1,000,000. If the offered value is not within range, throw an exception and do not create the Homeowners object. Policy deductible as a percentage of total insured value (structure + contents) Acceptable values are at least 0.01 and no more than 0.10. If the offered value is not within range, throw an exception and do not create the Homeowners object. Boolean indicating if policy is tied to umbrella coverage private contents: int private deduct : double private umbrella: boolean Description Null constructor: establishes no instance variable values Constructor accepts values and returns a reference to a Homeowners object. Operations public Homeowners : Homeowners public Homeowners String own, String insd, String nbr, double prem, String addr, int type, int struct int goods, double ded, boolean umbr ): Homeowners public getDeductInDollars ) : double Returns the dollar value of the deductible as: structure + contents deductible public calcExposure(): double public calccurrentvalue]: double Returns a double value representing the total possible exposure if the contract becomes immediately, wholly payable. For HomeOuners policies, this is calculated as the sum of structure and contents. Returns a double value representing the current total book value of the contract. For Homeowners policies, this calculated as: premium - (calcExposure exposureRate public tostring]: String Returns a string reference to a formatted description of the Homeowners object: owner owns Policy polNbr insuring insured, with a premium of polPren. This Homeowners policy insures a type propType home at propAddress. The structure is insured for sstructure ; contents for $contents. The deductible is sgetDedcut.InDollars. This policy is is not part of an umbrella contract. Use a stringBuilder object. Use the superclass tostring method for the first part of the output.Explanation / Answer
I am assuming you needed to add the changes related to four attributes in the picture - i.e. propType, structure, contents and deduct which are highlighted in the picture. Please let me know if I am missing something in comments..I'll help for sure...
InvalidParameterForHomeException.java
public class InvalidParameterForHomeException extends Exception {
public InvalidParameterForHomeException(String string) {
super(string);
}
}
HomeOwners.java
public class HomeOwners extends Policy {
private double exposureRate; // current exposureRate for HomeOwners Policy
private String propAddress; // legal address of insured property
private int propType; // numeric code describing property type
private int structure; // structure coverage limit, stated in thousands of
// dollars
private int contents; // contents limits, stated in thousands of dollars
private double deduct; // policy deductible as a percentage of total insured
// value
private boolean umbrella; // boolean indicating if policy is tied to
// umbrella coverage
public HomeOwners() {
super();
}// end null constructor
public HomeOwners(String own, // owed to super class
String insd, // owed to super class
String nbr, // owed to super class
double prem, // owed to super class
String addr, // subclass homewoners variable
int type, // subclass homewoners variable
int struct, // subclass homewoners variable
int goods, // subclass homewoners variable
double ded, // subclass homewoners variable
boolean umbr) // subclass homewoners variable
{
super(own, insd, nbr, prem);
setExposureRate();
setPropAddress(addr);
setPropType(type);
setStructure(struct);
setContents(goods);
setDeduct(ded);
setUmbrella(umbr);
}// end full constructor
/*
* SET METHODS
*/
public final void setPropAddress(String addr) {
propAddress = addr;
}// end setPropAddress
public final void setPropType(int type) {
if (type < 1 || type > 4)
propType = 1;
else
propType = type;
}// end setProType
public final void setStructure(int struct) {
if (struct < 0 || struct > 10000000)
throw new InvalidParameterForHomeException("Structure Coverage limit is invalid.");
else
structure = struct;
}// end setStructure
public final void setContents(int goods) {
if (goods < 0 || goods > 1000000)
throw new InvalidParameterForHomeException("Content Limit is invalid.");
else
contents = goods;
}// end setContent
public final void setDeduct(double ded) {
if (ded < 0.01 || ded > 0.10)
throw new InvalidParameterForHomeException("Policy Dedcutible Percentage is invalid.");
else
deduct = ded;
}// end setDeduct
public final void setUmbrella(boolean umbr) {
umbrella = umbr;
}// end setUmbrella
public final void setExposureRate() {
exposureRate = .0025;
}// END exposureRate
/*
* GET METHODS
*/
public final String getPropAddress() {
return propAddress;
}// end getPropAddress
public final int getPropType() {
return propType;
}// end getProType
public final int getStructure() {
return structure * 1000;
}// end getStructure
public final int getContents() {
return contents * 1000;
}// end getContent
public final double getDeduct() {
return deduct;
}// end getDeduct
public final boolean getUmbrella() {
return umbrella;
}// end getUmbrella
public final double getExposureRate() {
return exposureRate;
}// END getExposureRate
public final double getDeductInDollars() {
return ((getStructure() + getContents()) * getDeduct());
}// End getDeductInDollars
/*
* OTHER METHODS
*/
public double calcExposure() {
return (getStructure() + getContents());
}// End calExposure
public double calcCurrentValue() {
return getPolPrem() - (calcExposure() * getExposureRate());
}// End calcCurrentValue
public String toString() {
String testUmbrella; // Stores a string related to boolean umbrella
if (getUmbrella()) {
testUmbrella = "This policy is part of an Umbrella contract";
} else {
testUmbrella = "This policy is not part of an Umbrella contract";
}
return String.format(
"%n " + super.toString() + "This Homewners policy insures a type %d home at %s. "
+ "The structure is insured for $%,.2f; contents for $%,.2f. " + "The dudctible is $%,.2f %s",
getPropType(), getPropAddress(), (double) getStructure(), (double) getContents(), getDeductInDollars(),
testUmbrella);
}// END toString
}// End Class
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.