Class Game
java.lang.Object
edu.ntnu.idatt1002.k2g05.models.games.Game
- All Implemented Interfaces:
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 -
Method Summary
Modifier and TypeMethodDescriptionboolean
addScore
(int score) Method for adding a score to the gamedouble
getMean()
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
getSum()
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.
-
Constructor Details
-
Game
Constructor for creating an instance of a Game.- Parameters:
player
- the player who played
-
Game
Constructor for creating an instance of a Game.- Parameters:
player
- the player who playedscores
- list of scores the player has played.
-
-
Method Details
-
getPlayer
Gets the player that has played the game.- Returns:
-
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 toscore
- to add.
-