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: 3860138 • 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

package policy;

public class PolicyHolder {

   private int policyNumber;
   private int age;
   private int noAccidents;
  
   public PolicyHolder(){
       super();
       this.policyNumber = 0;
       this.age = 0;
       this.noAccidents = 0;
   }
  
   public PolicyHolder(int policyNumber, int age, int noAccidents) {
       this.policyNumber = policyNumber;
       if(age<14 || age>125){
           System.out.println("Invalid Age! Settting to 0");
           age = 0;
       }
       this.age = age;
       this.noAccidents = noAccidents;
   }

   public int getPolicyNumber() {
       return policyNumber;
   }

   public void setPolicyNumber(int policyNumber) {
       this.policyNumber = policyNumber;
   }

   public int getAge() {
       return age;
   }

   public void setAge(int age) {
       if(age<14 || age>125){
           System.out.println("Invalid Age! Settting to 0");
           age = 0;
       }
       this.age = age;
   }

   public int getNoAccidents() {
       return noAccidents;
   }

   public void setNoAccidents(int noAccidents) {
       this.noAccidents = noAccidents;
   }

   public void print(){
       System.out.println("Policy Number: "+this.policyNumber);
       System.out.println("Age: "+this.age);
       System.out.println("Number of accident involved: "+this.noAccidents);
   }
  
   public void checkAccident(PolicyHolder ph){
      
       if(ph.getAge()>35 && ph.getNoAccidents() <= 1){
           ph.print();
       }
   }
   public static void main(String[] args) {
      
      
       PolicyHolder newPolicyHolder = new PolicyHolder();
      
       PolicyHolder newPolicyHolder1 = new PolicyHolder(1,50,0);
       PolicyHolder newPolicyHolder2 = new PolicyHolder(2,24,3);
      
       newPolicyHolder.checkAccident(newPolicyHolder);
       newPolicyHolder1.checkAccident(newPolicyHolder1);
       newPolicyHolder2.checkAccident(newPolicyHolder2);
      

   }

}

Output:

Policy Number: 1
Age: 50
Number of accident involved: 0

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