Skip to content

Instantly share code, notes, and snippets.

@fteychene
Last active May 28, 2019 14:09
Show Gist options
  • Select an option

  • Save fteychene/bae64c6dafa90e87443ed031196d6c9e to your computer and use it in GitHub Desktop.

Select an option

Save fteychene/bae64c6dafa90e87443ed031196d6c9e to your computer and use it in GitHub Desktop.
Bowling game

Bowling Rules

The game consists of 10 frames.
In each frame the player has two rolls to knock down 10 pins.
The score for the frame is the total number of pins knocked down, plus bonuses for strikes and spares.

A spare is when the player knocks down all 10 pins in two rolls.
The bonus for that frame is the number of pins knocked down by the next roll.

A strike is when the player knocks down all 10 pins on his first roll.
The frame is then completed with a single roll.
The bonus for that frame is the value of the next two rolls.

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.

Requirements

Write a class Game that has two methods

void roll(int) is called each time the player rolls a ball. The argument is the number of pins knocked down.
int score() returns the total score for that game.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment