Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA: In this exercise, you will re-create the graphics version of classic race of the tortoise and the hare for a Two-lap race. You will

JAVA: In this exercise, you will re-create the graphics version of classic race of the tortoise and the hare for a Two-lap race. You will use random number generation to develop a simulation of this memorable event. You will also add two buttons (Start and Stop) for your race. User should be able to click on the buttons using Mouse or keyboard shortcut (of your choice) to press the buttons. Simulate two mountains by drawing a line that extends from bottom-right corner of the window to the midpoint of line from center of the screen to the right end and then to the bottom-center point. Similarly draw the second mountain from bottom-center to midpoint of a line from center to left end of the screen and from there to bottom right corner (See the figure above showing two mountains). The tortoise and the hare should race up the first mountain (towards your right hand side) and then race down from that mountain and continue onto second mountain. This process will be repeated in reverse. For each lap, they will start at the bottom of the mountain, race up to the top, and continue racing until they reach down to the end of first mountain and then continue onto the second mountain. Implement the graphical output to actually print the tortoise and the hare on the arc for every move (See below for details). Our contenders begin the race at square 1 of 640 squares. Each square represents a possible position along the race course. The top of the mountain is at square 160. The first contender to reach or pass square 160 (top) will continue moving in downward direction. The first contender to cross or pass the square 320 will continue onto the second mountain. The first contender to cross or pass the square 640 will change direction and then continue in the reverse direction. The winner reaches the starting point first (i.e., bottom left corner). The winner is rewarded with a pail of fresh carrots and lettuce. The course weaves its way up (and down) the side of a slippery mountain, so occasionally the contenders lose ground. There is a clock that ticks 2 times per second. With each tick of the clock, your program should adjust the position of the animals according to the rules in table below. Animal Move Type Percentage of the time Actual Move Tortoise Fast plod 45% 3 squares to the left Slip 15% 6 squares to the right Slow Plod 30% 1 square to the left Hare Sleep 20% No move at all Big hop 10% 8 squares to the left Big Slip 10% 10 squares to the right Small hop 30% 1 square to the left Small slip 30% 2 square to the right Use variables to keep track of the positions of the animals (i.e., position numbers are 1640). Start each animal at position 1 (i.e., the starting gate). If an animal slips right before square 1, move the animal back to square 1. Generate the percentages in the preceding table by producing a random integer i in the range 1 ?i ?10. For the tortoise, perform a fast plod when 1 ?i ?5, a slip when 6 ?i ?7 or a slow plod when 8 ?i ?10. Use a similar technique to move the hare. Begin the race by printing (when Start Button is pressed) BANG !!!!! AND THEY'RE OFF !!!!! For each tick of the clock (i.e., each repetition of a loop), print a 640-position line showing the letter T in the tortoises position and the letter H in the hares position. At the top left corner of your screen, display lap numbers and position numbers for both animals. Occasionally, the contenders land on the same square. In this case, the tortoise bites the hare and your program should print OUCH!!! All print positions other than the T, the H or the OUCH!!! (in case of a tie) should be blank. After printing each line, test whether either animal has reached or passed square 160. If so, continue down the mountain till the bottom of mountain. After both mountains are covered, turn around and start the running in opposite direction right away. Print the winner and terminate the simulation if any animal reaches the end of reverse travel (i.e., reaches the starting point of the race). If the tortoise wins, print TORTOISE WINS!!! YAY!!! If the hare wins, print HARE WINS! YUCH! If both animals win on the same clock tick, you may want to favor the tortoise (the underdog), or you may want to print, ITS A TIE. If neither animal wins, perform the loop again to simulate the next tick of the clock.

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

SQL Database Programming

Authors: Chris Fehily

1st Edition

1937842312, 978-1937842314

More Books

Students also viewed these Databases questions

Question

Determine miller indices of plane A Z a/2 X a/2 a/2 Y

Answered: 1 week ago