Question: 18. ^MUST CONTAIN while() statement to ALLOW multiple input^ ****PLEASE INCLUDE COMMENTS IN CODE (so that I can understand why you did certain things)***** Obiective
18.


^MUST CONTAIN while() statement to ALLOW multiple input^
****PLEASE INCLUDE COMMENTS IN CODE (so that I can understand why you did certain things)*****
Obiective 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 horse's 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. MichaelJacksone 14 false Firstname1 8 true Runner2 1 false BiteTheDust3 2 true ElkRacer4 4 false IWine 5 true HorseNamel 11 false KillerTheHorse2 6 false Seabiscut3 5 true Seabiscut4 1 true Winner: (Firstnamel, 8) Eligible: (Firstname1, 8) (teTheDust3, 2) Winner: (IWine, 5) Eligible: (IWin, 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 Cas shown on the last page of this document). The HorseRace class should have a main method (public static void main String D args) t) and a static Horse raceO) method that simulates a race of Horses. The race method returns the winning eligible horse The main method should keep reading lines CTHERE 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 Cand store it into an array) 2. I 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 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 Cand 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 getSpeedO 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 "C" + name +-, .. + speed + ") ". Obiective 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 horse's 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. MichaelJacksone 14 false Firstname1 8 true Runner2 1 false BiteTheDust3 2 true ElkRacer4 4 false IWine 5 true HorseNamel 11 false KillerTheHorse2 6 false Seabiscut3 5 true Seabiscut4 1 true Winner: (Firstnamel, 8) Eligible: (Firstname1, 8) (teTheDust3, 2) Winner: (IWine, 5) Eligible: (IWin, 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 Cas shown on the last page of this document). The HorseRace class should have a main method (public static void main String D args) t) and a static Horse raceO) method that simulates a race of Horses. The race method returns the winning eligible horse The main method should keep reading lines CTHERE 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 Cand store it into an array) 2. I 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 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 Cand 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 getSpeedO 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 "C" + name +-, .. + speed + ")
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
