java.lang.Object
edu.ntnu.idatt1002.k2g05.models.games.Game
All Implemented Interfaces:
Serializable

public class Game extends Object implements Serializable
A class that holds a game, a game is composed of several scores, a score is the sum of all the throws in a play.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Game(Player player)
    Constructor for creating an instance of a Game.
    Game(Player player, List<Integer> scores)
    Constructor for creating an instance of a Game.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    addScore(int score)
    Method for adding a score to the game
    double
    Returns the arithmetic average of all the scores.
    Gets the player that has played the game.
    Method for getting all the scores that a player has played.
    int
    Returns the sum of all scores.
    int
    removeScore(int index)
    Removes the score at the specified position in this list.
    void
    setScore(int index, int score)
    Method for setting a score at a index, if index is out of bounds it will add scores to fit to index.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Game

      public Game(Player player)
      Constructor for creating an instance of a Game.
      Parameters:
      player - the player who played
    • Game

      public Game(Player player, List<Integer> scores)
      Constructor for creating an instance of a Game.
      Parameters:
      player - the player who played
      scores - list of scores the player has played.
  • Method Details

    • getPlayer

      public Player getPlayer()
      Gets the player that has played the game.
      Returns:
    • getScores

      public List<Integer> getScores()
      Method for getting all the scores that a player has played.
      Returns:
      all the scores.
    • addScore

      public boolean addScore(int score)
      Method for adding a score to the game
      Parameters:
      score - to be added. must be between 0 and 300
      Returns:
      true if this collection changed as a result of the call
    • removeScore

      public int removeScore(int index)
      Removes the score at the specified position in this list. Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list. Params:
      Parameters:
      index - – the index of the element to be removed
      Returns:
      the score previously at the specified position Throws: IndexOutOfBoundsException – if the index is out of range
    • getSum

      public int getSum()
      Returns the sum of all scores.
      Returns:
      sum
    • getMean

      public double getMean()
      Returns the arithmetic average of all the scores.
      Returns:
      the mean
    • setScore

      public void setScore(int index, int score)
      Method for setting a score at a index, if index is out of bounds it will add scores to fit to index.
      Parameters:
      index - to be added to
      score - to add.