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

In this problem you will recreate the class race of the turtle and the hare. You

ID: 3671046 • Letter: I

Question

In this problem you will recreate the class race of the turtle and the hare. You will use random number generation and method development to simulate this event. Our contenders begin that race at position 1. Their destination, i.e. the finish line, is at position 60. The first contender to reach or past position 60 is rewarded with a pail of fresh carrots and lecttuce. The course weaves its way up the side of a slippery mountain, so occasionally the contenders lose ground and slip. They try to make up for those occasional slips by fast plods (the turtle) and big hops (the hare). Our hare is so sure of his advantage over the turtle that he take short naps every now and then. In each step of the race the position of the animals should be adjusted according to the following rules:

Use variables to keep track of the positions of the animals (i.e. position nymber are 1-60). Start each animal at position 1 (i.e. the "starting gate"). If an animal slips back before square 1, move the animal back to square 1. If the animal advances past the finish line, set the position to square 60. For each step of the race (i.e. each repetition of a loop), print a line showing the letter T in the position of the turtle and a line showing the letter H in the position of the hare. All positions other than the T or the H should be blank. After each line is printed, test if either animal has reached or passed square 60. If so, print the winner and terminate the simulation. Otherwise, the race continues.

Your program should implement and use the following methods:

1. public int moveTurtle( int pos, int finishLine ), 2. public int moveHare( int pos, int finishLine ), 3. public void printCurrentPositions( int turtlePos, int harePos)

The first two functions take in the current position of the turtle/hare and, based on randomly generated number, compute the new position following the rules in the table above. The third function takes position of both animals and produce the "image" on the screen reflecting the current state of the race. The main method needs to repeatedly call these three methods until one of the animals reaches the finish line (at position 60).

Animal Move type Percentage of the time Actual Move Turtle Fast plod 37% 3 squares forward Slip 35% 6 squares backward Slow plod 28% 1 square forward Hare Sleep 18% No move Big hop 15% 9 squares forward Big slip 15% 12 squares backward Small hop 35% 1 square forward Small slip 17% 2 square backword

Explanation / Answer

#include #include int main() { int i; int i2; int hare = 0; int tortiose = 0; int finish = 1; int race; printf("The race between the Tortiose and the Hare! On your mark, get set, Bang !!! "); printf("And they are off! "); srand(time(NULL)); i=rand()%10 +1; i2=rand()%10 +1; for(race=1; tortiose !=finish && hare!=finish; race++) { //Moving the tortiose if(8
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