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

. The DriveRite Insurance Company provides automobile insurance policies for dri

ID: 3843570 • Letter: #

Question

.      The DriveRite Insurance Company provides automobile insurance policies for drivers. Design a single class diagram showing the class, the application program, the relationship between the two, and multiplicity. Insert the completed class diagram into a Word document. Then write the pseudocode as described below. Be sure to follow the CSI 117 Style Criteria (Links to an external site.) for naming conventions, class diagrams, pseudocode, keywords, and operators.

a.      Create a PolicyHolder class that contains a policy number, customer age, and the number of accidents in which the driver has been involved in the last three years. Include the following:

i.       A default constructor that initializes each attribute to some reasonable default value for a non-existent policy holder.

ii.     Another constructor method that has a parameter for each data member, called the overloaded constructor. This constructor initializes each attribute to the value provided when an object of this type is instantiated. If the customer's age is not between 14 and 125 inclusive, then display an error message and set the age to 0.

iii.   Accessor and mutator methods for each attribute. For the age mutator, if the customer's age is not between 14 and 125 inclusive, then set the age to 0, since this is obviously an error.

iv.   A method that displays all the data about a policy holder.

b.     An application program that contains two modules: the main() module and the checkAccident() module.

Include instructions in the main() module to do the following:

i.       Create and initialize a PolicyHolder object using the default constructor, naming it newPolicyHolder. Call the appropriate methods to initialize all the data members for the newPolicyHolder object, choosing appropriate values.

ii.     Create and initialize 2 different PolicyHolder objects using the overloaded constructor. Choose appropriate values for the attributes for each of the two PolicyHolder objects.

iii.   Call the checkAccident() method for each PolicyHolder object, so there will be 3 calls to the checkAccident() method.

The checkAccident() module must do the following:

i.       Accept a PolicyHolder argument (i.e., it has a parameter declared using PolicyHolder as the data type).

ii.     Display all the data for any policy holder that is over 35 years old and has one accident or less.

Explanation / Answer

This is PolicyHolder class

package com.automobile_insurance_policies_for_drivers;

public class PolicyHolder {

   int policy_number;
   int customer_age;
   int number_of_accidents;
  
  
   //default constructor
   public PolicyHolder() {
       super();
       // TODO Auto-generated constructor stub
       this.policy_number =0;
       this.customer_age = 0;
       this.number_of_accidents = 0;
   }
  
   //Overloaded constructor
   public PolicyHolder(int policy_number, int customer_age,
           int number_of_accidents) {
       super();
       this.policy_number = policy_number;
       if(customer_age<125 && customer_age>14){
           this.customer_age = customer_age;
       }else{
           this.customer_age=0;
           System.out.println(" Customer age is not valid must be between 14 to 125");
       }
      
       this.number_of_accidents = number_of_accidents;
   }

   public int getPolicy_number() {
       return policy_number;
   }
   public void setPolicy_number(int policy_number) {
       this.policy_number = policy_number;
   }
  
   public int getCustomer_age() {
       return customer_age;
   }
   public void setCustomer_age(int customer_age) {
       if(customer_age<125 && customer_age>14){
           this.customer_age = customer_age;
       }else{
           this.customer_age=0;
           System.out.println(" Customer age is not valid must be between 14 to 125");
       }
   }
  
   public int getNumber_of_accidents() {
       return number_of_accidents;
   }
   public void setNumber_of_accidents(int number_of_accidents) {
       this.number_of_accidents = number_of_accidents;
   }
  
  
   public void checkAccident(PolicyHolder policyholder){
  
       this.policy_number = policyholder.policy_number;
       this.customer_age = policyholder.customer_age;
       this.number_of_accidents = policyholder.number_of_accidents;
      
      
      
       System.out.println(" Policy holder no.: "+policy_number);
       System.out.println("Custtomer age: "+customer_age);
       System.out.println("Number of accident: "+number_of_accidents);
      
   }
  
}

This is Test class including both module

package com.automobile_insurance_policies_for_drivers;

import java.awt.Polygon;

public class Test {

   public static void main(String[] args) {
       // TODO Auto-generated method stub

       //PolicyHolder object using the default constructor
       PolicyHolder ph=new PolicyHolder();
      
       // 1st PolicyHolder objects using the overloaded constructor
       PolicyHolder ph1=new PolicyHolder(1, 50, 2);
       //call method
       ph.checkAccident(ph1);
      
       //2 nd PolicyHolder objects using the overloaded constructor
       PolicyHolder ph2=new PolicyHolder(2, 130, 5);
       //call method
       ph.checkAccident(ph2);
   }

}

Output:


Policy holder no.: 1
Custtomer age: 50
Number of accident: 2

Customer age is not valid must be between 14 to 125

Policy holder no.: 2
Custtomer age: 0
Number of accident: 5