Question: Test_Policy.java /* * This is a test harness for the Policy class. * * This process will exercise all methods included in the Policy class:




Test_Policy.java
/* * This is a test harness for the Policy class. * * This process will exercise all methods included in the Policy class: * > null constructor * > full constructor * -- all set methods * > toString * -- all get methods * -- txtPolType method * * This process will use an array type to hold Policy objects and an enhanced for loop. * * */ public class Test_Policy { /* * Global scoping for varialbes/data structures is STRONGLY DISCOURAGED, but here it makes * our lives (and code) simpler, so we'll allow it. * COMPLETE THE FOLLOWING ARRAY DECLARATION */ private static /* * The main method will only 'direct traffic' from this point forward. * This main calls one method to build/load the array and a second method to process it. */ public static void main( String[] args ) { buildArray( ); printToStrings( ); } // end main /* * The buildArray method instantiates 6 Policy objects and stores them in the globally * declared array. * The first object instantiated will use the null constructor; all remaining objects will * call the full constructor of Policy. * Thus, both constructors and all set methods will be tested. */ private static void buildArray( ) { grpPolicy[0] = new Policy( ); // Call null constructor grpPolicy[1] = new Policy( "Ted Arroway", // Call full constructor, which will call all set "Ted Arroway", // methods "HO658542", 2, 2563.58 ); grpPolicy[2] = new Policy( "Eleanor Arroway", "Eleanor Arroway", "AU002584", 1, 1503.27 ); grpPolicy[3] = new Policy( "Drumlin, LLC", "David Drumlin", "HO963214", 2, 5980.73 ); grpPolicy[4] = new Policy( "Hadden Industries", "S.R. Hadden", "HO658542", 2, 9870.85 ); grpPolicy[5] = new Policy( "Palmer Joss", "Palmer Joss", "AU456852", 1, 813.79 ); } // end buildArray /* * The printToStrings method will call the toString method of each object in the array and output * the formatted String object provided. * Thus, the toString method, the txtPolType method, and all get methods will be tested. */ private static void printToStrings( ) { System.out.printf( "%n%nList of Policy Objects in Array grpPolicy%n%n" ); // Add the control statement for the ENHANCED FOR LOOP here for { System.out.printf( "%s%n", oneContract.toString( ) ); } // end for loop } // end printToStrings } // end Test_Policy
Expected Output PA01 List of Policy Objects in Array grpPolicy null owns Policy null, a(n) HOMEOWNERS policy, insuring null, with a premium of $0.00 Ted Arroway owns Policy H0658542, a(n) HOMEOWNERS policy, insuring Ted Arroway, with a premium of $2,563.58 Eleanor Arroway owns Policy AU802584, a(n) AUTO policy, insuring Eleanor Arroway, with a premium of $1,503.27. Drumlin, LLC owns Policy H0963214, a(n) HOMEOWNERS policy, insuring David Drumlin, with a premium of $5,980.73 Hadden Industries owns Policy H0658542, a(n) HOMEOWNERS policy, insuring S.R. Hadden, with a premium of $9,870.85. Palmer Joss owns Policy AU456852, a(n) AUTO policy, insuring Palmer Joss, with a premium of $813.79
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
