Java program that calculates the score of a game of bowling (also known as “ten - pin bowling”)
The BowlingGame class represents a single bowling game.
Each game has 10 frames by default, but 2 bonus frames are awarded if last frame was a strike/spare. So, a game can have a maximum of 12 frames and a minimum of 10.
-
void roll (int pins)
- Updates the frames based on the number of pins knocked in each roll -
boolean isValidRoll(int pins, int attempt)
- Checks if the pins knocked are valid for this attempt -
int getScore()
- Returns the current score of the game -
boolean isFinished()
- Indicates wheather the game is finished or not -
boolean isStrike(int attempt)
- Checks if the attempt is a strike -
boolean isSpare(int attempt)
- Checks if the attempt is a spare
The frame class represents a single frame of the 10 - pin Bowling game score board.
Each frame has 2 rolls. The total points for the frame is calculated after all rolls (including bonus rolls)
boolean isStrike()
- Getter methodvoid setStrike(boolean isStrike)
- Setter methodboolean isSpare()
- Getter methodvoid setSpare(boolean isSpare)
- Setter methodint getTemp()
- Getter methodint getFirstRoll()
- Getter methodvoid setFirstRoll(int firstRoll)
- Setter methodint getSecondRoll()
- Getter methodvoid setSecondRoll(int secondRoll)
- Setter methodint getBonus()
- Getter methodvoid setBonus(int bonus)
- Setter methodint getPoints()
- Getter methodvoid setPoints(int points)
- Setter methodvoid decreaseBonus()
- Decreases the bonus by 1void addToTemp(int val)
- Adds a number to temp and updates it's value
The class with main method, to test the program