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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//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

Add a comment
Know the answer?
Add Answer to:
The Drive‑Rite Insurance Company provides automobile insurance policies for drivers. Design a single class diagram showing...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • MAKE IT DIFFERENT WAYS TO RUN IT: Design an application for each of the following problems...

    MAKE IT DIFFERENT WAYS TO RUN IT: Design an application for each of the following problems writing the pseudocode for each; include a UML diagram if appropriate. Be sure to follow the CSI 117 Style Criteria for naming conventions, class diagrams, pseudocode, keywords, and operators. 1. Wood Trim, Inc. wants a program that will allow its sales clerks to enter the length (in feet) of the trim ordered by a customer and the price of one foot of trim. Design...

  • Showy Shiny Shoe Store The Showy Shiny Shoe Store sells different styles of shoes, such as...

    Showy Shiny Shoe Store The Showy Shiny Shoe Store sells different styles of shoes, such as sandals and walking shoes. Each style of shoe is offered in different colors, such as brown and black. Available shoe sizes range from size 5 to size 11, in both whole and half sizes. Design an object-oriented computer program by doing the following: Create a class diagram (a UML diagram) for the Shoes class that contains the style of the shoes, the color of...

  • In C++, Step 1: Implement the Student Class and write a simple main() driver program to...

    In C++, Step 1: Implement the Student Class and write a simple main() driver program to instantiate several objects of this class, populate each object, and display the information for each object. The defintion of the student class should be written in an individual header (i.e. student.h) file and the implementation of the methods of the student class should be written in a corresponding source (i.e. student.cpp) file. Student class - The name of the class should be Student. -...

  • Create a UML diagram to help design the class described in exercise 3 below. Do this...

    Create a UML diagram to help design the class described in exercise 3 below. Do this exercise before you attempt to code the solution. Think about what instance variables will be required to describe a Baby class object; should they be private or public? Determine what class methods are required; should they be private or public? Write Java code for a Baby class. A Baby has a name of type String and an age of type integer. Supply two constructors:...

  • Create a UML diagram to help design the class described in exercise 3 below. Do this...

    Create a UML diagram to help design the class described in exercise 3 below. Do this exercise before you attempt to code the solution. Think about what instance variables will be required to describe a Baby class object; should they be private or public? Determine what class methods are required; should they be private or public? 3. Write Java code for a Baby class. A Baby has a name of type String and an age of type integer. Supply two...

  • PYTHON Task 1 Create a class called Window It has 2 public properties 1 private property...

    PYTHON Task 1 Create a class called Window It has 2 public properties 1 private property 1 constructor that takes 3 arguments pass each argument to the appropriate property Task 2 In a new file import the Window class Instantiate the Window object Output the two public properties Task 3 Alter the Window class in Task 1 Add an accessor and mutator (the ability to access and change) to the private property Task 4 Create a class named Instrument Give...

  • using CSCI300 java Given the following UML Class Diagram Club_Card # card_num : String # name...

    using CSCI300 java Given the following UML Class Diagram Club_Card # card_num : String # name : String # age: int # year: int + Club_Card (all parameters) + Setters & Getters + toString() : String + equals(x: Object): boolean [10 pts] Define the class Club_Card, which contains: 1. All arguments constructor which accepts all required arguments from the main and instantiate a Club_Card object. 2. Set & get method for each data attribute. 3. A toString() method which returns...

  • PLEASE YOU PYTHON 3 TO SOLVE! THANKS! PLEASE YOU PYTHON 3 TO SOLVE! THANKS! Example 1...

    PLEASE YOU PYTHON 3 TO SOLVE! THANKS! PLEASE YOU PYTHON 3 TO SOLVE! THANKS! Example 1 Design a class named Information that holds the following personal data: .name, age, address (this attribute has a default value of “unknown"), and phone number. . All the attributes are defined as private. • Write appropriate accessor and mutator methods. • Complete the definition of the str_ method, such that it displays each Information object's data in the following format: name: "Sarah Jones” –...

  • JAVA The following is about creating a class Ruler and testing it. ​​(i) Create a class...

    JAVA The following is about creating a class Ruler and testing it. ​​(i) Create a class Ruler with the attributes brand (which is a string) and length (an integer) which are used to store the brand and length of the ruler respectively. Write a constructor Ruler(String brand, int length) which assigns the brand and length appropriately. Write also the getter/setter methods of the two attributes. Save the content under an appropriate file name. Copy the content of the file as...

  • In Java please Create a class to represent a dog. Name the class “Dog”. It will...

    In Java please Create a class to represent a dog. Name the class “Dog”. It will contain three (3) class attributes, its bark, size, and cuteness. The bark will be the sound of the dog’s bark, as in “woof!”. Its size will be how tall the dog is from the ground, and that number should always be between 6 and 44 inches. The cuteness is a string describing how cute the dog is, based on this scale: “ugliest dog ever!”...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT