

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Program Due: Monday, November 12, 2001 Purpose: The purpose of this assignment is to give you practice using threads, exception handling, and multimedia. Problem: This is a simulation of a race between a tortoise and a hare. In this problem you will recreate one of the truly great moments in history, namely the classic race of the tortoise and the hare. You will use random number generation to develop the simulation and each animal will be on a separate thread. At the beginning of the race, call the start methods for each of the threads. Use wait, notify, and notifyAll to synchronize the animal’s activities. Incorporate at least two types of multimedia of your choice to make your program more interesting. You will need to use exception handling where appropriate. Details to follow. 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 the 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. There is a clock that ticks once per second. With each tick of the clock, your program should adjust the position of the animals according to the following rules: Animal Move type Percentage of the time Actual move Tortoise Fast plod 50% 3 squares to the right Slip 20% 6 squares to the left Slow plod 30% 1 square to the right Hare Sleep 20% No moves at all Big hop 20% 9 squares to the right Big slip 10% 12 squares to the left Small hop 30% 1 square to the right Small slip 20% 2 squares to the left Use variables to keep track of the positions of the animals (i.e., position numbers are 1-70). Start each animal at position1 (i.e., the “starting gate”). If an animal slips left 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 BANG!!!! AND THEY’RE OFF !!!!
Then, for each tick of the clock (i.e., each repetition of a loop), print 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 program should print OUCH !!! beginning at that position. All print positions other than T, the H or the OUCH!! (in case of a tie) 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. If the tortoise wins, print TORTOISE WINS !! YAY! If the hare wins, print hare wins, yuch. If both animals win on the same tick of the clock, you may want to favor the turtle (the underdog) or you may want to print IT’S A TIE!!. If neither animal wins, perform the loop again to simulate the next tick of the clock. Once you get your program running, enhance it with graphics, sounds, animations, etc. Have fun and be creative! We will run a few of the best programs in class in a few weeks. Documentation : Submit all documentation in a two-pocket folder labeled on the cover with your name and section and date submitted. Always turn your programming assignments into the lecture class (not the lab). Using the outline on the Program Submission Sheet, you should include hard copies of your documentation: Problem description Problem analysis Data diagram (replacing flowcharts from CIS 120) Pseudocode for driver class and appropriate methods Test design Test results Code (note important new categories under the code section) A floppy disk should also be included and clipped to and inside one of the pockets of your folder. The floppy disk should include: All documentation files except the test results containing graphical data that may be too large to fit on the floppy. All program files: source code (.java files), object code (.class files), or other files. REMEMBER to ANALYZE and DESIGN FIRST, (now your tasks are decomposed) NEXT do one task at a time, keep back-ups of all your files, use version control, ... ... AND GET STARTED TODAY!