Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please Answer: CSC350 Organization of Programming Languages Spring 2022 Assignment 1 Due: Jan. 23, 2022 (Sunday) Turtle and Hare Race (Use C++ or Java to

Please Answer:

image text in transcribed

CSC350 Organization of Programming Languages Spring 2022 Assignment 1 Due: Jan. 23, 2022 (Sunday) Turtle and Hare Race (Use C++ or Java to implement) In this problem you will recreate the classic race of the turtle and the hare. You will use random number generation and method development to simulate this event. Our contenders begin the race at position 1. Their destination, i.e. the finish line, is at position 70. The first contender to reach or pass position 70 is rewarded with a pail of fresh carrots and lettuce. 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 takes 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: Animal Move type Percentage of the time Actual move Turtle Fast plod 34% 4 squares forward Slip 36% 5 squares backward Slow plod 30% 2 square forward Hare Sleep 20% Big hop 15% 10 squares forward Big slip 17% 12 squares backward 30% 1 square forward Small slip 18% 2 squares backward No move Small hop Use variables to keep track of the positions of the animals (i.e., position numbers are 170). 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 70. 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 70. 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 move Turtle ( int pos , int finishLine) 2 public int moveHare (int pos, int finishLine) 3 public void printCurrent Positions (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 positions of both animals and produces the "image" on the screen reflecting the current state of the race. You may also do text mode, using T for turtle and H for hare. The main method needs to repeatedly call these three methods until one of the animals reaches the finish line (at position 70)

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

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions