Overview: The Penny Pitch program is reminiscent of a carnival game where pennies are tossed onto a board with squares containing prizes. Once a penny lands on a square, the player receives the prize on that square. In this simulation of the game, when the player clicks Toss, the computer randomly chooses one of the 25 squares on the board. The player then receives the points on that square and a 'P' replaces the value on the board to indicate that a penny has landed there. If during a toss, a penny has already landed on a square, then nothing happens and the board remains the same and no points are gained. In the game you are writing, the player will get 20 tosses. After each toss the total points are updated and after the 20th toss, the total points and a "Game Over" message appear in a message box. The goal of our game is just to get as many points as possible. The reset button is only necessary if a person wants to start a new game before a game is finished. The game should be automatically reset after the 20th turn.
Assignment: Write the code for a Penny Pitch applet which will replicate the applet at the right. Here are the steps you will need to follow:
Step 1. Go to email and find my email for the Square.java PennyPitch.java starter file.
Step 2. Save the PennyPitch.java to your applets folder in your Eclipse workspace on your hard drive and the PennyPitch.html file to your Applets folder on the WebServ.
Step 3. Start by writing the code for the model class Square in Square.java. This class only defines the property of a square. The Square class does not define or utilize a two-dimensional array in any way. The two-dimensional array of 25 squares named board has 5 rows and 5 columns and will be declared and instantiated in the view class file PennyPitch.java. Here is what you need to do in the Square class:
Step 4. Write the code for the view class in PennyPitch.java. This is the driver and will define the GUI interface for the applet. In it you will instantiate a two-dimensional array to hold square objects and process input from the user to run the game as specified in the web page description. Don't panic! You won't get this done in a couple of minutes. Take your time and think through the problem. You will write code for the following methods in PennyPitch.java:
Step 5. Export the two files into a jar file named PennyPitch.jar and place it into your applets folder on the WebServ and then use the accompanying PennyPitch.html file to load your applet on the WebServ.