(Solved) : Example Like Sample Input Sample Output Rapid 2 14 Speedy 2 14 1 2 1 4 1 3 0 1 1 1 1 3 1 2 Q32942149 . . .
so for example like;
Sample InputSample OutputRapid 2 14 Speedy 2 14 1 2 1 4 1 3 0 1 1 1 1 3 1 2 1 4 1 4 1 20 1 1 2 1 1 1 2 1 1 1 1R: 1 2 S: 1 4 R: 1 3 S: 0 1 R: 1 1 S: 1 3 R: 1 2 S: 1 4 R: 1 4S: 1 2 R: 0 1 S: 1 2 R: 1 1 S: 1 2 R: 1 1 S: 1 1Tie! in 8 rounds!
HOW CAN I WRITE A Demo CLASS CALLED RacerDemo INJAVA FOR THIS CLASS BELOW? THESE ARE THEINSTRUCTIONS
Then create a Racer demo class. You will readin the attributes of the two racer objects. Then you will continueto read in a direction and number to move for racer object 1,followed by a direction number to move racer object 2 while keepingtrack of each racer. Direction will always be entered in as 0(backwards) or 1 (forward) no matter what type of character eachRacer is. Move will always between 1 and 4 regardless of thecharacter type of the Racer. You should handle all inputlimitations in the Racer Class.
After each racer moves, check to see if there is a winner andadd the moves (direction and read in steps) to a String that willbe printed out after a winner/tie is declared. Continue to read innumbers representing direction/move for each racer until a winneris declared. Then print out the String with the pairs ofdirection/moves for each racer and who won (or tied) and in (n)number of turns. See the output. Please note, that after theinput/output table, there are two images that goes with the firstand second input/output examples, so you can see visually how thetwo racers move along a straight line. This is just to show youvisually what happens after each move; however, for thisassignment, you only need to supply the final String of moves andthe winner to avoid problems of output that can happen inCodio.
HERE IS THE CLASS
public class Racer extends Player{
private int steps;
private int direction;
private int character;
Racer(String n, int ch, int m){
super(n, m);
character = ch;
direction = 0;
}
/**
* @return the steps
*/
public int getSteps() {
return steps;
}
/**
* @return the direction
*/
public int getDirection() {
return direction;
}
/**
* @return the character
*/
public int getCharacter() {
return character;
}
/**
* @param steps the steps to set
*/
public void setSteps(int steps) {
this.steps = steps;
}
/**
* @param direction the direction to set
*/
public void setDirection(int direction) {
this.direction = direction;
}
/**
* @param character the character to set
*/
public void setCharacter(int character) {
this.character = character;
}
public void move(int n, int d){
if(character==1){
steps = 2;
direction = 1;
}
else{
steps = 4;
direction = 0;
}
}
}
Expert Answer
Answer to Example Like Sample Input Sample Output Rapid 2 14 Speedy 2 14 1 2 1 4 1 3 0 1 1 1 1 3 1 2 Q32942149 . . .
OR