Does my code have any errors? I feel pretty confident.
//Define a class PolicyHolder
class PolicyHolder
{
//Declare variable
private int policy_Number;
//Declare variable
private int customer_Age;
//Declare variable
private int number_Of_Accidents;
//Define a constructor
public PolicyHolder(int policy_Number, int customer_Age,int number_Of_Accidents)
{
//Set policy number
this.policy_Number = policy_Number;
//Set number of accidents
this.number_Of_Accidents = number_Of_Accidents;
//If customers age is greater than or equals 14 and less than or equals 125 */
if(customer_Age >= 14 && customer_Age <= 125)
//Set customer age
this.customer_Age = customer_Age;
else
//Set age
this.customer_Age = 0;
}
//Define a constructor
public PolicyHolder()
{
//Set value
this.number_Of_accidents = 0;
//Create new random value
Random randomGenerator = newRandom();
//Set value
this.policy_Number = randomGenerator.nextInt(100);
}
//Define a method "getPolicy_Number()"
public int getPolicy_Number()
{
//Return value
return policy_Number;
}
//Define a method "setPolicy_Number()"
public void setPolicy_Number(intPolicy_Number)
{
//Set value
this.policy_Number = policy_Number;
}
//Define a method "getCustomer_Age()"
public int getCustomer_Age()
{
//Return age
return customer_Age;
}
//Define a method "setCustomer_Age()"
public void setCustomer_Age(int customer_Age)
{
//If customers age is greater than or equal to 14 less than or equal 125 less than or equals 125 */
if(customer_Age >= 14 && customer_Age <= 125)
//Set age
this.customer_Age = customer_Age;
else
//Set age as 0
this.customer_Age = 0;
}
//Define a method "toString()"
public String toString()
{
//Return value
return "PolicyHolder[policy_Number=" + policy_Number
+ ",customer_Age=" + customer_Age + ",number_Of)Accidents=" number_Of_Accidents="
+ number_Of_Accidents + "]";
}
//Define a method "getNumber_Of_Accidents()"
public int getNumber_Of_Accidents()
{
//Return accidents count
return number_Of_Accidents;
}
//Define a method "setNumber_Of_Accidents()"
public void setNumber_Of_Accidents(int number_Of_Accidents)
{
//Set value
this.number_Of_Accidents = number_Of_Accidents;
}
}
//Define a class
public class TestPolicyHolder
{
//Define main method
public static void main(String[]args)
{
//create a new instance
PolicyHolder newPolicyHolder = new PolicyHolder();
//Define new value
PolicyHolder policyHolder1 = new PolicyHolder(123, 38, 1);
//Define new value
PolicyHolder policyHolder2 = new PolicyHolder(234, 29, 3);
//Call "checkAccident()"
checkAccident(newPolicyHolder);
//Call "checkAccident()"
checkAccident(policyHolder1);
//Call "checkAccident()"
checkAccident(policyHolder2);
}
//Define a method "checkAccident()"
public static void checkAccident(PolicyHolder policyHolder)
{
//If age is greater than 35 and less than or equals 1
if(policyHolder.getCustomer_Age() > 35 && policyHolder.getNumber_Of_Accidents() <= 1)
{
//Display value
System.out.println(policyHolder.toString());
}
}
Dear Student ,
As per the requirement submitted above , kindly find the below solution.
Here a new java program with name "PolicyHolder.java" is created, which contains following code.
PolicyHolder.java :
import java.util.Random;
//Define a class PolicyHolder
class PolicyHolder {
//Declare variable
private int policy_Number;
// Declare variable
private int customer_Age;
// Declare variable
private int number_Of_Accidents;
// Define a constructor
public PolicyHolder(int policy_Number, int
customer_Age, int number_Of_Accidents) {
// Set policy number
this.policy_Number =
policy_Number;
// Set number of accidents
this.number_Of_Accidents =
number_Of_Accidents;
// If customers age is greater than
or equals 14 and less than or equals 125 */
if (customer_Age >= 14
&& customer_Age <= 125)
// Set customer
age
this.customer_Age = customer_Age;
else
// Set age
this.customer_Age = 0;
}
// Define a constructor
public PolicyHolder() {
// Set value
this.number_Of_Accidents = 0;
// Create new random value
Random randomGenerator = new
Random();
// Set value
this.policy_Number =
randomGenerator.nextInt(100);
}
//Define a method "getPolicy_Number()"
public int getPolicy_Number() {
// Return value
return policy_Number;
}
//Define a method "setPolicy_Number()"
public void setPolicy_Number(int Policy_Number)
{
// Set value
this.policy_Number =
Policy_Number;
}
//Define a method "getCustomer_Age()"
public int getCustomer_Age() {
// Return age
return customer_Age;
}
// Define a method "setCustomer_Age()"
public void setCustomer_Age(int customer_Age) {
// If customers age is greater than
or equal to 14 less than or equal 125 less
// than or equals 125 */
if (customer_Age >= 14
&& customer_Age <= 125)
// Set age
this.customer_Age = customer_Age;
else
// Set age as
0
this.customer_Age = 0;
}
// Define a method "toString()"
public String toString()
{
//Return value
return
"PolicyHolder[policy_Number=" + policy_Number +
",customer_Age="+customer_Age +
",number_Of_Accidents="+number_Of_Accidents+"]";
}
//Define a method "getNumber_Of_Accidents()"
public int getNumber_Of_Accidents() {
//Return accidents count
return number_Of_Accidents;
}
//Define a method "setNumber_Of_Accidents()"
public void setNumber_Of_Accidents(int
number_Of_Accidents) {
// Set value
this.number_Of_Accidents =
number_Of_Accidents;
}
}
**********************************
TestPolicyHolder.java :
//Define a class
public class TestPolicyHolder {
//Define main method
public static void main(String[] args) {
//create a new instance
PolicyHolder newPolicyHolder = new
PolicyHolder();
//Define new value
PolicyHolder policyHolder1 = new
PolicyHolder(123, 38, 1);
//Define new value
PolicyHolder policyHolder2 = new
PolicyHolder(234, 29, 3);
//Call "checkAccident()"
checkAccident(newPolicyHolder);
//Call "checkAccident()"
checkAccident(policyHolder1);
//Call "checkAccident()"
checkAccident(policyHolder2);
}
//Define a method "checkAccident()"
public static void checkAccident(PolicyHolder
policyHolder) {
//If age is greater than 35 and less than or equals 1
if (policyHolder.getCustomer_Age()
> 35 && policyHolder.getNumber_Of_Accidents() <= 1)
{
//Display value
System.out.println(policyHolder.toString());
}
}
}
======================================================
Output : Compile and Run above program to get the screen as shown below
Screen 1 :TestPolicyHolder.java

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.
Does my code have any errors? I feel pretty confident. //Define a class PolicyHolder class PolicyHolder...
Java Homework Help. Can someone please fix my code and have my
program compile correctly? Thanks for the help.
Specifications:
The class should have an int field named monthNumber that holds
the number of the month. For example, January would be 1, February
would be 2, and so forth. In addition, provide the following
methods.
A no- arg constructor that sets the monthNumber field to 1.
A constructor that accepts the number of the month as an
argument. It should...
In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in 'Dog' : name (String type) age (int type) 2. declare the constructor for the 'Dog' class that takes two input parameters and uses these input parameters to initialize the instance variables 3. create another class called 'Driver' and inside the main method, declare two variables of type 'Dog' and call them 'myDog' and 'yourDog', then assign two variables to two instance of 'Dog' with...
The current code I have is the following: package uml; public class uml { public static void main(String[] args) { // TODO Auto-generated method stub } } class Account { private String accountID; public Account(String accountID) { this.accountID = accountID; } public String getAccountID() { return accountID; } public void setAccountID(String accountID) { this.accountID = accountID; } @Override public String toString() { return "Account [accountID=" + accountID + "]"; } } class SuppliesAccount extends Account { private...
Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the concept of a college course, assuming that a course has following attributers: code (for instance COSC1337), a description, and a number of credits (for instance 3). Include a constructor, the accessors, mutators and methods ‘toString’, ‘equals’, and ‘finalize’. Write a client class to test the behavior of the class and its methods. The outline of the class is given as follows: public class Course...
Please help with Java programming!
This code is to implement a Clock class.
Use my beginning code below to test your
implementation.
public class Clock {
// Declare your fields here
/**
* The constructor builds a Clock object and sets time to
00:00
* and the alarm to 00:00, also.
*
*/
public Clock() {
setHr(0);
setMin(0);
setAlarmHr(0);
setAlarmMin(0);
}
/**
* setHr() will validate and set the value of the hr field
* for the clock.
*
*...
You are to create a class Appointment.java that will have the following: 5 Instance variables: private String month private int day private int year private int hour private int minute 1 default constructor public Appointment() 1 non-default constructor that accepts arguments for all instance variables, your constructor must call the setter methods below to set the values of the instance variables public Appointment(String monthPassed, int dayPassed, int yearPassed, int hourPassed, int minutePassed) 5 setter methods (one for each instance variable)...
fisrt one is bicycle.java second code is bicycleapp.java can anyone help this??? please save my life Before you begin, DOWNLOAD the files “Lab8_Bicycle.java” and “Lab8_BicycleApp.java” from Canvas to your network drive (not the local hard drive or desktop). Once you have the files saved, RENAME THE FILES Bicycle.java and BicycleApp.java then open each file. 1) Look at the Bicycle class. Two of the many data properties we could use to define a bike are its color and the gear it...
In Java Create a testing class that does the following to the given codes below: To demonstrate polymorphism do the following: Create an arraylist to hold 4 base class objects Populate the arraylist with one object of each data type Code a loop that will process each element of the arraylist Call the first ‘common functionality’ method Call the second ‘common functionality’ method Call the third ‘common functionality’ method Verify that each of these method calls produces unique results Call...
I need help writing my main method**** Computer Science 111 Introduction to Algorithms and Programming: Java Programming Project #4 – Classes and Objects (20 Points) You will create 3 new classes for this project, two will be chosen from the list below and one will be an entirely new class you invent.Here is the list: Shirt Shoe Wine Book Song Bicycle VideoGame Plant Car FootBall Boat Computer WebSite Movie Beer Pants TVShow MotorCycle Design First Create three (3) UML diagrams...
C# Language The ColourControl Class The class should be public. The class defines a read-only or private set public property named Value of type int. The class defines a public event named ValueChanged whose delegate type is void with two parameters, object sender and EventArgs e. The public constructor for the class is a default constructor (i.e., takes no parameters). The constructor sets the Value property to 128. The class defines a public void method named IncreaseValue. The method increases...