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

2. The Drive-Rite Insurance Company provides automobile insurance policies for d

ID: 3862504 • Letter: 2

Question

2. The Drive-Rite 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. 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. Amethod that displays all the data about a policy holder.

Explanation / Answer

Based on all the info i could extract from the above problem, i'm providing this code, which runs successfully to the best of my knowledge. Make sure that both the java files are in the same package.

// PolicyHolder.java

public class PolicyHolder {
   private final int policy_no;
   int customer_age;
   int no_of_accidents;
  
   // default Constructor to initialize non existing customers
   public PolicyHolder(){
       policy_no = 0;
       customer_age = 0;
       no_of_accidents = 0;
   }
  
   // Parameterized Constructor to assign given values to data members
   public PolicyHolder(int policyNo, int customerAge, int noOfAccidents){
       policy_no = policyNo;
      
       // for "age" attribute, check if the value lies between 14 and 125, or not by calling age_mutator method
       customer_age = age_mutator(customerAge);
      
       no_of_accidents = noOfAccidents;
   }
  
   //Age-Mutator method - To check if the input age meets the given condition
   public int age_mutator(int custom_age){
       if(custom_age < 14 || custom_age > 125 ){  
           System.out.println(" The entered Age is not Valid! Setting the Age to Default!");
           return 0;
       }
       else
           return custom_age;
   }
  
   //Method to display all the data belonging to a customer
   public void display_data(){
       System.out.println("Policy Number: " + policy_no);
       System.out.println("Age of the Customer: " + customer_age);
       System.out.println("Number of Accidents been involved in: " + no_of_accidents + " ");
   }
}

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

// Application.java

public class Application {
   public static void main(String[] args){
      
       PolicyHolder newPolicyHolder = new PolicyHolder();
       checkAccident(newPolicyHolder);
      
      
       PolicyHolder testObj1 = new PolicyHolder(1403, 45, 1);
       checkAccident(testObj1);
      
       PolicyHolder testObj2 = new PolicyHolder(1503, 26, 3);
       testObj2.display_data();
   }
  
   // Module-2: checkAccident Method
   // The "checkAccident class has been made static so that we can call it without
   // having to declare an object of the Application class
   public static void checkAccident(PolicyHolder compObj){
       if(compObj.customer_age >= 35 && compObj.no_of_accidents <= 1){
           compObj.display_data();
       }
       else
           System.out.println("Failed to meet the conditions! No data to Display! ");
   }
}

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