Directions
You must create two Java files. One is called LastNameFirstNameWeek6Prog.java, and the other is called Horse.java.
Ensure you include ALL files required to make your program compile and run. I would like to see your .java files only.
Horse.java Class File
1. Create a new class called Horse that includes the functionality below
2. The new class has the attributes of:
name – Horse’s name, type String
age – age of Horse in years, type integer
height – height of Horse in meters, type double
color - type Horse’s color, type String
pureBlood - type boolean - true if Horse is pure blood, false if not
name – Horse’s name, type String
age – age of Horse in years, type integer
height – height of Horse in meters, type double
color - type Horse’s color, type String
pureBlood - type boolean - true if Horse is pure blood, false if not
3. Be sure your classes have a good set of accessor and mutator methods. Every member variable must have at least one independent accessor and one independent mutator.
4. Example:
public void setName(String name) mutator used to set name
public void seAge(int age) mutator used to set the age
//…. Add other mutator methods here
public String getName() accessor used to get name
public int getAge() accessor used to get age
//…. Add other accessor methods here
Ensure you use the “this” reference from within this class when referring to every instance variable or instance method of the current object.
public void setName(String name) mutator used to set name
public void seAge(int age) mutator used to set the age
//…. Add other mutator methods here
public String getName() accessor used to get name
public int getAge() accessor used to get age
//…. Add other accessor methods here
Ensure you use the “this” reference from within this class when referring to every instance variable or instance method of the current object.
LastNameFirstNameWeek6Prog.java Class File (Driver Program)
Write a driver program that reads in 3 animals of type Horse and prints out the name, age and height of all non pure blood Horse objects that are 4 or more years old. The following information should be read per Horse:
name
age
height
color
pureBlood
name
age
height
color
pureBlood
Conditional statements should be used to decide which Horse’s information should be printed.
Use accessor methods to check the age and pure blood status on each Horse.
Upload your page to the Dropbox.
NOTE: Complete your activity and submit it to the Dropbox by clicking on the Dropboxtab at the top of the course frame and choosing the correct Weekly Activity.
If needed, click on the Help button above for more information on Course Tools/Using theDropbox.
If needed, click on the Help button above for more information on Course Tools/Using theDropbox.
Total Possible Points
Example output of your program
Example Run:
Enter the name of Horse1: chip
Enter the age of Horse1 in years: 1
Enter the height (in meters) of Horse1: 2
Enter the color of Horse1: grey
Is Horse1 a pure blood? true or false?: true
Enter the name of Horse2: munk
Enter the age of Horse2 in years: 4
Enter the height (in meters) of Horse2: 1.5
Enter the color of Horse2: white
Is Horse2 a pure blood? true or false?: true
Enter the name of Horse3: bluetooth
Enter the age of Horse3 in years: 5
Enter the height (in meters) of Horse3: 2.5
Enter the color of Horse3: red
Is Horse3 a pure blood? true or false?: false
Enter the name of Horse1: chip
Enter the age of Horse1 in years: 1
Enter the height (in meters) of Horse1: 2
Enter the color of Horse1: grey
Is Horse1 a pure blood? true or false?: true
Enter the name of Horse2: munk
Enter the age of Horse2 in years: 4
Enter the height (in meters) of Horse2: 1.5
Enter the color of Horse2: white
Is Horse2 a pure blood? true or false?: true
Enter the name of Horse3: bluetooth
Enter the age of Horse3 in years: 5
Enter the height (in meters) of Horse3: 2.5
Enter the color of Horse3: red
Is Horse3 a pure blood? true or false?: false
The non pure blood Horses over 4 years old are:
Name: bluetooth
Age: 5
Height: 2.5
Name: bluetooth
Age: 5
Height: 2.5