Question
The Drive‑Rite Insurance Company provides automobile insurance policies for drivers. Design a single class diagram showing...
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. Be sure to follow the CSI 117 Style Criteria (Links to an external site.)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.
Answers
//Test java program
//PolicyHolderDriver.java
public class PolicyHolderDriver
{
public static void main(String[] args)
{
//Create a default constructor
PolicyHolder newPolicyHolder=new PolicyHolder();
//set values for newpolicyholder object
newPolicyHolder.setPolicyNumber("Premium-777");
newPolicyHolder.setAge(38);
newPolicyHolder.setAccidentCount(3);
//create two more Policyholder objects with parameter values
PolicyHolder pholder1=new PolicyHolder("Lack-1", 33, 1);
PolicyHolder pholder2=new PolicyHolder("Lack-11", 36, 2);
//calling checkAccident method for 3 objects
checkAccident(newPolicyHolder);
checkAccident(pholder1);
checkAccident(pholder2);
}/**
* Method that takes policyholder and check if age
* is above 35 then print details of policy holder.
* */
private static void checkAccident(PolicyHolder holder) {
if(holder.getAge()>35)
{
System.out.println("Details of policy holder");
System.out.println("Policy Holder whose age >35");
holder.display();
}
}//end ofmethod
}//end of class--------------------------------------------------------------------------------------------
//PolicyHolder.java
public class PolicyHolder
{
private String policyNumber;
private int age;
private int numaccidents;
//default constructor
public PolicyHolder()
{
//default values
policyNumber="####";
age=0;
numaccidents=0;
}
//Parameter constructor
public PolicyHolder(String policyNumber,
int age, int numaccidents) {
this.policyNumber=policyNumber;
if(age<14 || age >125)
age=0;
else
this.age=age;
this.numaccidents=numaccidents;
}
//Setter method for policy number
public void setPolicyNumber(String policyNumber)
{
this.policyNumber=policyNumber;
}
//Getter method policy number
public String getPolicyNumber()
{
return policyNumber;
}
//Setter method for age
public void setAge(int age)
{
if(age<14 || age >125)
age=0;
else
this.age=age;
}
//Getter method for age
public int getAge()
{
return age;
}
//Setter method for number of accidents
public void setAccidentCount(int numaccidents)
{
this.numaccidents=numaccidents;
}
//Getter method for number of accidents
public int getAccidentCount()
{
return numaccidents;
}
//Display object values
public void display() {
System.out.printf("Policy Number : %s\n",policyNumber);
System.out.printf("Age : %s\n",age);
System.out.printf("# of Accidents : %s\n",numaccidents);
}
}--------------------------------------------------------------------------------------------
Sample Output screenshot:
Class Diagram for PolicyHolder