Question
I am stuck on my java code, please help! What is the java code for this PA? Instructions: UML DIAGRAM: Old ResidencePolicy Code: public class
I am stuck on my java code, please help! What is the java code for this PA?
Instructions:
UML DIAGRAM:
Old ResidencePolicy Code:
public class ResidencePolicy { private String owner; private String group; private int number; private String address; private int type; private double premium; public ResidencePolicy() { this.owner = ""; this.group = ""; this.number = 0; this.address = ""; this.type = 0; this.premium = 0; }
public ResidencePolicy(String own, String grp, int nbr, String addr, int kind, double prem) { this.owner = own; this.group = grp; this.number = nbr; this.address = addr; this.type = kind; this.premium = prem; }
public void setOwner(String owner) { this.owner = owner; }
public void setGroup(String group) { this.group = group; }
public void setNumber(int number) { this.number = number; }
public void setAddress(String address) { this.address = address; }
public void setType(int type) { this.type = type; }
public void setPremium(double premium) { this.premium = premium; }
public String getOwner() { return owner; }
public String getGroup() { return group; }
public int getNumber() { return number; }
public String getAddress() { return address; }
public int getType() { return type; }
public double getPremium() { return premium; } public String txtType() { if(getType() == 1) return "HOMEOWNERS"; else if(getType() == 2) return "RENTERS"; else return "UNKNOWN"; }
public String toString() { return(getOwner() + " owns Residence Policy " + getNumber() + ", a(n) " + txtType() + " policy, issued by " + getGroup() + ", at physical address " + getAddress() + ", for a premium of $" + String.format("%,.2f", getPremium()) + "."); } }
Test_ResidencePolicy_Hierarchy code:
/* * This test harness will exercise all of the methods of the ResidencePoicy HIERARCHY * * (c) 2020, Terri Davis */ public class Test_ResidencePolicy_Hierarchy { /* * Global scoping for variables/data structures is STRONGLY DISCOURAGED, but here it makes * our lives (and code) simpler, so we'll allow it. */ private static ResidencePolicy[] objectArray = new ResidencePolicy[6]; /* * The main method should never do the bulk of the work; it should "direct traffic" for the methods * doing the bulk of the work. We'll start using this more modular (and easier to maintain) style * of structure here. * This main calls one method to build/load the array and a second method to process it. */ public static void main( String[] args ) { /*----------------------------------------------------------------------------------------------- * The first call in the main method calls executable code to check that minimal coding * standards have been followed */ PA02_Stds_Check.checkCode( ); //----------------------------------------------------------------------------------------------- buildArray( ); // "Load" the array with Policy objects examineObjects( ); // Output the return from the toString method of each Policy object } // end main /* * The buildArray method instantiates 6 objects of the ResidencePolicy hierarchy and stores them * in the globally declared array. */ private static void buildArray( ) { objectArray[0] = new HomeOwners( ); // Call null constructor // Call the full constructor objectArray[1] = new HomeOwners( "Ted Arroway", // Owed to SUPERclass "MUT", // Owed to SUPERclass 658542, // Owed to SUPERclass "2487 Morning Glory", // Owed to SUPERclass 2563.58, // Owed to SUPERclass 1, // SUBCLASS instance value 250, // SUBCLASS instance value 25, // SUBCLASS instance value 0.10, // SUBCLASS instance value false ); // SUBCLASS instance value objectArray[2] = new HomeOwners( "SR Hadden", "LLOYDS", 870054, "3500 SkyView", 13502.57, 4, 2500, 500, 0.15, true ); objectArray[3] = new Renters( ); objectArray[4] = new Renters( "Eleanor Arroway", "CIC", 983214, "5843 Arecibo Way #25A", 508.43, 25, 500, false ); objectArray[5] = new Renters( "Palmer Joss", "MUT", 831726, "984 Ave K Apt 8942", 754.36, 75, 500, true ); } // end buildArray /* * The examineObjects method will call the toString, totalContractRisk, and riskPremRation methods * of each object in the array and output the information returned in a formatted String. */ private static void examineObjects( ) { System.out.printf( "%n%nList of ResidencePolicy Objects in Array objectArray%n%n" ); for( ResidencePolicy oneObject: objectArray ) { System.out.printf( "%s", oneObject.toString( ) ); System.out.printf( "\t\tTotal Risk: $%,.2f\t\tRisk Ratio: %.6f%n%n", oneObject.totalContractRisk( ), oneObject.riskPremRatio( ) ); } // end for loop } // end examineObjects } // end Test_ResidencePolicy_Hierarchy
Expected Output:
Programming Assignment 02 Superclasses, subclasses, Inheritance, and Polymorphism Contents Given Tasks. Requirements ResidencePolicy.java.. Renters.java................ Homeowners.java... Test_ResidencePolicy_BookValue.java... Testing Your Code.................... .................... Submitting Your Work .. ........... ... Given: UML Class Diagrams: ResidencePolicy Home Owners O Renters Test harness shell: Test_ResidencePolicy_Hierarchy.java Executable (used in test harness shell) to check minimum standards adherence: PAB2_Stds_Check.class These instructions Sample output Grading Rubric Tasks: 1. Modify ResidencePolicy from PADI so that it meets the revised requirements, as described in the UML 2. Code Renters and Home Owners, and Annuity to meet the UML requirements provided 3. Test your code using the provided test hamess. Requirements: ResidencePolicy.java 1. Revise ResidencePolicy to meet the revised UML requirements. 2. Remove all "dead" code. Renters.java 1. Write code for the subclass Renters according to the UML requirements as provided. 2. The first portion of the toString return in Renters should come from a call to the superclass method. Homeowners.java 1. Write code for the subclass Home Owners according to the UML requirements as provided. 2. The first portion of the toString return in Homeowners should come from a call to the superclass method. Test_ResidencePolicy_BookValue.java Full code has been provided for you in the test harness. Please note that it would be a VERY GOOD idea to add additional test cases to the array when testing your work. The first method call from the test harness will execute a check for adherence to minimum coding standards in the project code. The test harness cannot successfully compile unless the project code meets these minimal coding standards. Passing this check is not a guarantee that code meets all standards, just that the minimum standards required for grading have been met Attributes private owner: String private group: Strine private number: int private address: String private premium: double ResidencePolicy (abstract) Notes Policy owner's full, legal name A short alphanumeric code identify the "group" by which this policy is issued A unique numeric identifier for this policy The physical address associated with the policy (e.g. 1 UTSA Circle) Annual premium amount for policy I Operations public ResidencePolicy(): ResidencePolicy Description Null constructor; establishes no instance variable values. Returns a reference to a Policy object with neutral default values. Constructor accepts an argument or parameter per instance variable, calls set methods and establishes instance variable values as appropriate. Returns a reference to a fully instantiated Policy object. public ResidencePolicy( String own, String grp. int nbr, String addr, int kind, double prem): ResidencePolicy public riskPremRatio): double Returns a double value representing the ratio of premium to total contract risk. Formula to use: premium/totalContractRisk. Calcuation of risk is dependent on subclass type. public abstract totalContractRisk: double This abstract method is not defined in the superclass. Each subclass will have its own specific method of calculation public toString(): String Returns a String reference to a formatted description of the Policy object: owner owns className number, issued by group, at physical address address, for a premium of premium. NOTES: 1. When output in the toString method, premium must displayed with correct currency formatting, including thousands separator. 2. The type instance variable has been removed - this is being handled by breaking into subclasses. 3. The txt Type method has also been removed. See Note #2. |Attributes private homePropType: int Home Owners subclass of ResidencePolicy Notes Numeric code describing property type: 1 - single family dwelling 2-townhouse, attached 3-townhouse, detached 4- condominium Structural coverage limit, stated in thousands of dollars Contents limits, stated in thousands of dollars Policy deductible as a percentage of total insured value (homeStructure + homeContents) Boolean indicating if policy is tied to umbrella coverage private homeStructure: int private homeContents: int private homeDeductible: double private umbrella: boolean Description Null constructor; establishes no instance variable values Constructor accepts values and returns a reference to a Homeowners object. Operations Ipublic Homeowners(): Homeowners public Homeowners( String own, String grp. int nbr, String addr, double prem, int type, int struct, int goods, double ded, boolean umbr): Home Owners public get Text Type: String Returns a reference to a string object containing the human-readable text description for the homeProp Type instance value. public getDeductibleInDollars(): double Returns the dollar value of the deductible as: ((homeStructure +homeContents) 1000) homeDeductible public totalContractRisk(): double Concrete definition of the superclass abstract method. The formula for this subclass:(homeStructure + homeContents) 1000 ) - getDeductibleInDollars public toString(): String Returns a String reference to a formatted description of the Homeowners object: owner owns className number, issued by group, at physical address address, for a premium of premium. The insured residence is a getTextType with a structural value of $get HomeStructure and contents value of $get HomeContents. The deductible is $getDeductibleInDollars. The residence coverage is/is not part of an umbrella policy. NOTES: Inclusion to or exclusion from umbrella coverage is determined by the value of the umbrella instance variable. Structural and contents values are displayed in actual dollars, not thousands. Both of these values and the calculated deductible value must be currency formatted. NOTES: 1. Set & get methods are not listed here, but are assumed to be present. Further, standard naming is assumed 2. The first portion of the toString return will come from the superclass method 3. Direct access to instance values (outside set/get methods) is, as always, forbidden Attributes private renterContents: int private renterDeductible: int private renterReplaceRider: boolean Renters subclass of ResidencePolicy Notes Contents limits, stated in thousands of dollars Policy deductible as a dollar amount Boolean indicating if policy carries replacement coverage (if false, coverage is depreciated) Description Null constructor; establishes no instance variable values Constructor accepts values and returns a reference to a Renters object. Operations public Renters(): Renters public Renters String own, String grp. int nbr, String addr, double prem, int goods, int ded, boolean replace ): Renters public getTextReplace(): String Returns a reference to a string object whose contents are based on the renter ReplaceRider instance value. If the value is true, the returned String will be "Loss coverage at replacement value of lost property." if the value is false, the returned String will be "Loss coverage at depreciated value of lost property based on documented purchase date." public total ContractRisk(): double Concrete definition of the superclass abstract method. The formula for this subclass: renterContents * 1000 ) - renterDeductible public toString(): String Returns a String reference to a formatted description of the Homeowners object: owner owns className number, issued by group, at physical address address, for a premium of premium. The insured residence is rented with a contents value of $getRental Contents. The deductible is $getRental Deductible. getTextReplace NOTES: Values of renterContents and renterDeductible must be displayed with currency formatting NOTES: 1. Set & get methods are not listed here, but are assumed to be present. Further, standard naming is assumed 2. The first portion of the toString return will come from the superclass method 3. Direct access to instance values (outside set/get methods) is, as always, forbidden Expected Output using Provided Test Harness & Data Correct use of abstract keyword (class). Correct use of abstract keyword (method). Standards check finished. List of ResidencePolicy Objects in Array objectArray null owns Homeowners o, issued by null, at physical address null, for a premium of $0.00. The insured residence is a unknown structure type with a structural value of $0.00 and contents value of $0.00. The deductible is $0.00. The residence is not part of an umbrella policy. Total Risk: $0.00 Risk Ratio: NaN Ted Arroway owns HomeOwners 658542, issued by MUT, at physical address 2487 Morning Glory, for a premium of $2,563.58. The insured residence is a single family dwelling with a structural value of $250,000.00 and contents value of $25,000.00 The deductible is $27,500.00. The residence is not part of an umbrella policy. Total Risk: $247,500.00 Risk Ratio: 0.010358 SR Hadden owns HomeOwners 870054, issued by LLOYDS, at physical address 3500 SkyView, for a premium of $13,502.57. The insured residence is a condominium with a structural value of $2,500,000.00 and contents value of $500,000.00 The deductible is $450,000.00. The residence is part of an umbrella policy. Total Risk: $2,550,000.00 Risk Ratio: 0.005295 null owns Renters O, issued by null, at physical address null, for a premium of $0.00. The insured residence is rented with a contents value of $0.00. The deductible is $0.00. Loss coverage at depreciated value of lost property based on documented purchase date. Total Risk: $0.00 Risk Ratio: NaN Eleanor Arroway owns Renters 983214, issued by CIC, at physical address 5843 Arecibo Way #25A, for a premium of $508.43. The insured residence is rented with a contents value of $25000.00. The deductible is $500.00. Loss coverage at depreciated value of lost property based on documented purchase date. Total Risk: $24,500.00 Risk Ratio: 0.020752 Palmer Joss owns Renters 831726, issued by MUT, at physical address 984 Ave K Apt 8942, for a premium of $754.36. The insured residence is rented with a contents value of $75000.00. The deductible is $500.ee. Loss coverage at replacement value of lost property. Total Risk: $74,500.00 Risk Ratio: 0.010126
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