Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

Please use java to complete this program

Implement textbook (9/E) problem 7.28 in page 303. The problem statement is reproduced next:
7.28 (Simulation: The Tortoise and the Hare) In this problem, you'll re-create the classic race of the tortoise and the hare. You'll use random-number generation to develop a simulation of this memorable event. Our
contenders begin the race at square 1 of 70 squares. Each square represents a possible position along the race course. The finish line is at square 70. The first contender to reach or pass square 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. A clock ticks once per second. With each tick of the clock, your application
should adjust the position of the animals according to the rules in Fig. 7.32. Use variables to keep track of the positions of the animals (i. e., position numbers are 1-70). Start each animal at position 1 (the "starting gate").
If an animal slips left before square 1, move it back to square 1.
Animal
Tortoise
Move type
Hare
Fast plod
Slip
Slow plod
Sleep
Big hop
Big slip
Small hop
Small slip
Percentage of the time
50%
20%
30%
20%
20%
10% mart
30%
20%
Actual move
3 squares to the right
6 squares to the left
1 square to the right
No move at all
9 squares to the right
12 squares to the left
1 square to the right
2 squares to the left
Fig. 7.32 | Rules for adjusting the positions of the tortoise and the hare.
Generate the percentages in Fig. 7.32 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 displaying
BANG !!!!!
AND THEY'RE OFF !!!!!
Then, for each tick of the clock (i. e., each repetition of a loop), display a 70-position line showing the letter T in the position of the tortoise and the letter H in the position of the hare. Occasionally, the contenders will land
on the same square. In this case, the tortoise bites the hare, and your application should display OUCH!!! beginning at that position. All output positions other than the T, the H or the OUCH!!! (in case of a tie) should be
blank. After each line is displayed, test for whether either animal has reached or passed square 70. If so, display the winner and terminate the simulation. If the tortoise wins, display TORTOISE WINS!!! YAY!!! If the hare
wins, display Hare wins. Yuch. If both animals win on the same tick of the clock, you may want to favor the tortoise (the "underdog"), or you may want to display It's a tie. If neither animal wins, perform the loop again to
simulate the next tick of the clock.
When you're ready to run your application, assemble a group of fans to watch the race. You'll be amazed at how involved your audience gets! Later in the book, we introduce a number of Java capabilities, such as
graphics, images, animation, sound and multithreading. As you study those features, you might enjoy enhancing your tortoise-and-hare contest simulation.
expand button
Transcribed Image Text:Implement textbook (9/E) problem 7.28 in page 303. The problem statement is reproduced next: 7.28 (Simulation: The Tortoise and the Hare) In this problem, you'll re-create the classic race of the tortoise and the hare. You'll use random-number generation to develop a simulation of this memorable event. Our contenders begin the race at square 1 of 70 squares. Each square represents a possible position along the race course. The finish line is at square 70. The first contender to reach or pass square 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. A clock ticks once per second. With each tick of the clock, your application should adjust the position of the animals according to the rules in Fig. 7.32. Use variables to keep track of the positions of the animals (i. e., position numbers are 1-70). Start each animal at position 1 (the "starting gate"). If an animal slips left before square 1, move it back to square 1. Animal Tortoise Move type Hare Fast plod Slip Slow plod Sleep Big hop Big slip Small hop Small slip Percentage of the time 50% 20% 30% 20% 20% 10% mart 30% 20% Actual move 3 squares to the right 6 squares to the left 1 square to the right No move at all 9 squares to the right 12 squares to the left 1 square to the right 2 squares to the left Fig. 7.32 | Rules for adjusting the positions of the tortoise and the hare. Generate the percentages in Fig. 7.32 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 displaying BANG !!!!! AND THEY'RE OFF !!!!! Then, for each tick of the clock (i. e., each repetition of a loop), display a 70-position line showing the letter T in the position of the tortoise and the letter H in the position of the hare. Occasionally, the contenders will land on the same square. In this case, the tortoise bites the hare, and your application should display OUCH!!! beginning at that position. All output positions other than the T, the H or the OUCH!!! (in case of a tie) should be blank. After each line is displayed, test for whether either animal has reached or passed square 70. If so, display the winner and terminate the simulation. If the tortoise wins, display TORTOISE WINS!!! YAY!!! If the hare wins, display Hare wins. Yuch. If both animals win on the same tick of the clock, you may want to favor the tortoise (the "underdog"), or you may want to display It's a tie. If neither animal wins, perform the loop again to simulate the next tick of the clock. When you're ready to run your application, assemble a group of fans to watch the race. You'll be amazed at how involved your audience gets! Later in the book, we introduce a number of Java capabilities, such as graphics, images, animation, sound and multithreading. As you study those features, you might enjoy enhancing your tortoise-and-hare contest simulation.
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education