Overview | Schedule | Announcements | Resources | Assignments | Home |
Read |
The project simulation1 has an empty class called Bowling. You will implement a simple bowling simulation in stages. The game of bowling consists of throwing a heavy ball down an alley at a set of ten pins. A player bowls ten frames and, except for the tenth frame, has up to two throws per frame. If the player knocks down all ten pins on the first throw, the frame is complete. Otherwise, the player gets one more chance to knock down the rest of the pins. In the tenth frame, a bowler who knocks down ten pins on the first throw gets two additional throws; a bowler who knocks down a total of ten pins on the first two throws gets one additional throw. Otherwise, a bowler gets a total of two throws, as in any other frame. Note: Read the description above carefully, because our simulation simplifies the real-world rules of bowling; for example, there is no extra scoring for strikes or spares (apart from the handling of the tenth frame). In particular, be sure that you understand how the maximum score in our simulation is 120. |
Do |
Create the Bowling class by opening the class editor (double-click the Bowling class diagram) and create the class shell: public class Bowling { } Add the following fields: firstBall, secondBall, extraBall, frame, and score, all of which are of type int. The class constructor should initialize all of these to 0. |
Write a method called updateScore. It will add firstBall and secondBall to score. If it is the 10th frame, it will also add extraBall to score. |
|
Write a void method called displayFrame. It will display the frame number, the first and second throws, and the total score so far in the following format: Results for frame # 1 First ball: 8 Second ball: 2 Score so far: 10 If it is the 10th frame, it will display the frame as follows: **** This game is over - Final Score **** Results for frame # 10 First ball: 9 Second ball: 1 Extra ball: 6 Total for game: 95 Test this method before going to the next step of the lab. You may need to write temporary mutator methods to set firstBall, secondBall, extraBall and frame for the purpose of testing. |
|
Write a void method called bowlFrame:
|
|
Write a method called reset. This method will initialize firstBall, secondBall, extraBall, score, and frame to 0. |
|
Play |
To play a game, simply create an instance of Bowling, reset, and invoke bowlFrame 10 times. Play the game two or three times to make sure it works. Make sure you invoke reset between games. |
Do |
Write an int method for the Bowling class called playGame that invokes bowlFrame 10 times. playGame should reset before playing, and should return the score of the game as an int. |
Overview | Schedule | Announcements | Resources | Assignments | Home |
DePauw University , Computer Science
Department , Spring 2005
Maintained by Brian
Howard ( bhoward@depauw.edu
).
Last updated