Question: write a program that reads in lines from the input. (HorseRace) For every line, it creates a Horse object according to the instructions on the

write a program that reads in lines from the input. (HorseRace)

For every line, it creates a Horse object according to the instructions on the line. Then, it prints out the winner in a simulated race() command of horses.

The input will be oe or more sets of five lines. Each of the five lines will represent a different horse. The first word in the line should be the horse's name, then the horses speed, and last the eligibility of the horse in for the race. (boolean)

Output: For each set of five input lines will result in one line of output describing the participants and the winner and their speeds. The first horse is the winner and the rest are all eligible participants in order of input.

Sample Input

MichaelJackson0 14 false

Firstname1 8 true

Runner2 1 false

BiteTheDust3 2 true

ElkRacer4 4 false

IWin0 5 true

HorseName1 11 false

KillerTheHorse2 6 false

Seabiscut3 5 true

Seabiscut4 1 true

Sample Output

Winner: (Firstname1, 8) Eligible: (Firstname1, 8) (BiteTheDust3, 2) Winner: (IWin0, 5) Eligible: (IWin0, 5) (Seabiscut3, 5) (Seabiscut4, 1)

Now that you know what this program is to do, let us get into more details of what you need to do. See next page.

You will need to write code for TWO classes (a Horse class and a HorseRace class). Create them in the SAME java file (as shown on the last page of this document).

public HorseRace class

The HorseRace class should have a main method (public static void main(String [] args) {}) and a static Horse race() method that simulates a race of Horses. The race method returns the winning eligible horse.

The main method should keep reading lines (THERE MAY BE MANY SETS OF 5 HORSES)

// READ AND PROCESS FIVE LINES AT A TIME

1. // process each line and store the Horse object in an array a. it should read in the Horse name, speed and eligibility and create a new instance of a Horse (and store it into an array

2. // run a race (find the eligible horse with highest speed in the array)

3. // print the output a) print the winner b) print all the horses in the array

4. remember to print a final println after printing the horses for a set.

Horse class

DO NOTE create a separate java file for this. Put this at the end of the HorseRace java file as shown on next page. Do not make this public. Just declare are class Horse (and not as public class Horse).

1. The Horse class should have THREE private instance variables a String containing the name of the Horse a int variable containing the speed of the Horse a boolean variable to indicate the eligibility of the Horse

2. The Horse class should have FOUR methods

a. a constructor public Horse(String name, int speed, boolean eligibility) that will set the name, speed and eligibility variables of the Horse to the corresponding parameters.

b. public int getSpeed() that will return the speed of the horse.

c. public boolean isEligible() that returns true if the horse is eligible and false if it is not.

d. public String toString() that will return a String consisting of "(" + name + ", " + speed + ") ".

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!