Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Test_Policy.java /* * This is a test harness for the Policy class. * * This proc

ID: 3876906 • Letter: T

Question

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.

Explanation / Answer

//policy class

public class Policy {

  

   private String owner;

   private String insured;

   private String polNbr;

   private int polType;

   private double polPrem;

  

   public Policy() {

       // TODO Auto-generated constructor stub

   }

  

   /**

   * @param owner

   * @param insured

   * @param polNbr

   * @param polType

   * @param polPrem

   */

   public Policy(String owner, String insured, String polNbr, int polType, double polPrem) {

       super();

       this.owner = owner;

       this.insured = insured;

       this.polNbr = polNbr;

       this.polType = polType;

       this.polPrem = polPrem;

   }

   /**

   * @return the owner

   */

   public String getOwner() {

       return owner;

   }

   /**

   * @param owner the owner to set

   */

   public void setOwner(String owner) {

       this.owner = owner;

   }

   /**

   * @return the insured

   */

   public String getInsured() {

       return insured;

   }

   /**

   * @param insured the insured to set

   */

   public void setInsured(String insured) {

       this.insured = insured;

   }

   /**

   * @return the polNbr

   */

   public String getPolNbr() {

       return polNbr;

   }

   /**

   * @param polNbr the polNbr to set

   */

   public void setPolNbr(String polNbr) {

       this.polNbr = polNbr;

   }

   /**

   * @return the polType

   */

   public int getPolType() {

       return polType;

   }

   /**

   * @param polType the polType to set

   */

   public void setPolType(int polType) {

       this.polType = polType;

   }

   /**

   * @return the polPrem

   */

   public double getPolPrem() {

       return polPrem;

   }

   /**

   * @param polPrem the polPrem to set

   */

   public void setPolPrem(double polPrem) {

       this.polPrem = polPrem;

   }

   //return policy type as text

   public String txtPolType(){

       if (polType == 1){

           return "AUTO";

       }

       else{

           return "HOMEOWNERS";

       }

   }

   //toString: return policy detail as string

   public String toString() {

       return(owner +" owns Policy "+ polNbr + " a(n) "+txtPolType()+" policy,insuring"+insured + " , with a premium of " + polPrem +".");

   }

}

-----------------------------------------------------------------------------------------------------

//test_policy class

public class Test_Policy

{

/*

* ARRAY DECLARATION

*/

private static Policy[] grpPolicy = new Policy[6];

  

/*

* 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(Policy oneContract:grpPolicy)

{

System.out.printf( "%s%n",

oneContract.toString( ) );

} // end for loop

  

} // end printToStrings

  

} // end Test_Policy

-----------------------------------------------------------------------------------

sample output:

List of Policy Objects in Array grpPolicy

null owns Policy null a(n) HOMEOWNERS policy,insuringnull , with a premium of 0.0.

Ted Arroway owns Policy HO658542 a(n) HOMEOWNERS policy,insuringTed Arroway , with a premium of 2563.58.

Eleanor Arroway owns Policy AU002584 a(n) AUTO policy,insuringEleanor Arroway , with a premium of 1503.27.

Drumlin, LLC owns Policy HO963214 a(n) HOMEOWNERS policy,insuringDavid Drumlin , with a premium of 5980.73.

Hadden Industries owns Policy HO658542 a(n) HOMEOWNERS policy,insuringS.R. Hadden , with a premium of 9870.85.

Palmer Joss owns Policy AU456852 a(n) AUTO policy,insuringPalmer Joss , with a premium of 813.79.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote