Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Objective Write a program that reads in lines from the input. For every line, it creates a Horse object according to the instructions on

Java

Objective

Write a program that reads in lines from the input.

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 important part of this assignment is to make)use)of)the)Horse class. Details are given after an explanation of what the program is to do.

NOTE$THAT$AT$THE$END$OF$THIS$DOCUMENT$THERE$ARE INSTRUCTIONS$ON$HOW$TO$CREATE$MULTIPLE$ CLASSES$IN$ONE$FILE,$WHICH$WILL$BE$NEEDED$TO$SUBMIT$THIS$ASSIGNMENT.

Input

The input will be one 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 horses name, then the horses speed, and last the eligibility of the horse in for the race(boolean).

Example1: Lightning0 8 true

This represents a horse named Lightning0 with a speed of 8 and the value true signifies that this horse is eligible to race.

Example1: Donkey1 10 false

This represents a horse named Donkey1 with a speed of 10 and the value false signifies that this horse is not eligible to race.

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. You can assume that there will always be one eligible horse in each set.

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Contemporary Issues In Database Design And Information Systems Development

Authors: Keng Siau

1st Edition

1599042894, 978-1599042893

More Books

Students also viewed these Databases questions

Question

dy dx Find the derivative of the function y=(4x+3)5(2x+1)2.

Answered: 1 week ago

Question

Draw and explain the operation of LVDT for pressure measurement

Answered: 1 week ago