Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that reads in lines from the input. (HorseRace) For every line,

ID: 655220 • Letter: W

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 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.

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

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

Put this at the end of the HorseRace java file. 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 + ") ".

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)

Explanation / Answer

#include
#include
#include
#define NumberHorses 10// Number Horses
#define SpaceHorses 15 // How long is the race? 15 Spaces
#include // Delete this if you are using Linux or Mac, or any Unix console

// Function is for make the output. Something like this 1:Horse-----|
void showhorse(int HorseNumber, int HorsesPosition) {
int X;
printf(" %d:", HorseNumber);
for(X = 0 ; X = 1 && y printf("Start GO! ");
/*Srand generate a random number, but always is the same random number
so, you need to use the time to change every single time the random number*/
srand( (unsigned)time(NULL));

showhorse(1,Ha);
showhorse(2,Hb);
showhorse(3,Hc);
showhorse(4,Hq);
showhorse(5,Hw);
showhorse(6,He);
showhorse(7,Hr);
showhorse(8,Ht);
showhorse(9,Hy);
showhorse(10,Hu);

while(Ha < SpaceHorses && Hb < SpaceHorses && Hc < SpaceHorses && Hq < SpaceHorses && Hw < SpaceHorses && He < SpaceHorses && Hr < SpaceHorses && Ht < SpaceHorses && Hy < SpaceHorses && Hu < SpaceHorses) { if((rand () % 100)>50)
++Ha;
if((rand () % 100)>50)
++Hb;
if((rand () % 100)>50)
++Hc;
if((rand () % 100)>50)
++Hq;
if((rand () % 100)>50)
++Hw;
if((rand () % 100)>50)
++He;
if((rand () % 100)>50)
++Hr;
if((rand () % 100)>50)
++Ht;
if((rand () % 100)>50)
++Hy;
if((rand () % 100)>50)
++Hu;

printf(" ");
printf(" ======================= ");
showhorse(1,Ha);
showhorse(2,Hb);
showhorse(3,Hc);
showhorse(4,Hq);
showhorse(5,Hw);
showhorse(6,He);
showhorse(7,Hr);
showhorse(8,Ht);
showhorse(9,Hy);
showhorse(10,Hu);
printf(" =======================");
printf(" ");

Sleep(1200);/*Change this for this sleep(1); ,if you are using Linux
or Mac, or any Unix console */
}
if(Ha == 15 && Hb == 15 || Ha == 15 && Hc == 15 || Hc == 15 && Hb == 15 ) {
printf("Tie ");
}
else if (Ha == 15){
printf("Congratulations Horse 1 - Star ");
}
else if (Hb == 15){
printf("Congratulations Horse 2 - Dakota ");
}
else if (Hc == 15){
printf("Congratulations Horse 3 - Cheyenne ");
}
else if (Hq == 15){
printf("Congratulations Horse 4 - Spirit ");
}
else if (Hw == 15){
printf("Congratulations Horse 5 - Misty ");
}
else if (He == 15){
printf("Congratulations Horse 6 - Cowboy ");
}
else if (Hr == 15){
printf("Congratulations Horse 7 - Honey ");
}
else if (Ht == 15){
printf("Congratulations Horse 8 - Duke ");
}
else if (Hy == 15){
printf("Congratulations Horse 9 - Rocky ");
}
else if (Hu == 15){
printf("Congratulations Horse 10 - Lady ");
}
printf(" I hope that everybody enjoy the race, see you next time! ");
printf("============================================================== ");
printf(" By: <span class="wp-smiley wp-emoji wp-emoji-lol" title="XD">XD</span> Creations");
printf(" ");
printf(" ");

}

else {
printf("This horses is not in the race. Please try again and choose between 1 to 10. ");
}
system("PAUSE");
return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote