Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- A program to score a game of ten-pin Bowling.
- Write a class named "Game" that has two methods:
- - roll(pins) is called each time the player rolls a ball. The argument is the number of
- pins knocked down.
- - score() is called only at the very end of the game. It returns the total score for
- that game.
- Rules of ten-pin bowling:
- 1. The game consists of 10 frames. In each frame the player has two opportunities to
- knock down 10 pins. The score for the frame is the total number of pins knocked down,
- plus bonuses for strikes and spares.
- 2. A spare is when the player knocks down all 10 pins in two tries. The bonus for that
- frame is the number of pins knocked down by the next roll. So in frame 3 above, the
- score is 10 (the total number knocked down) plus a bonus of 5 (the number of pins
- knocked down on the next roll.)
- 3. A strike is when the player knocks down all 10 pins on his first try. The bonus for
- that frame is the value of the next two balls rolled.
- 4. In the tenth frame a player who rolls a spare or strike is allowed to roll the extra
- balls to complete the frame. However no more than three balls can be rolled in tenth
- frame.
- Steps in Test-Driven Development:
- 1. WRITE A FAILING TEST.
- Write the shortest possible failing test that exercises the desired behaviour.
- Observe it failing in the expected way.
- 2. MAKE IT PASS.
- Optimise for development speed. All tests should pass.
- 3. REFACTOR
- Optionally, refactor the code, ensuring that the tests continue to pass.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement