Question: NO ARRAYLISTS, just need help with the bolded methods public ScoreBoard(int gameCount){ //Constructor // set the game count and initialize the records to be an
NO ARRAYLISTS, just need help with the bolded methods
public ScoreBoard(int gameCount){
//Constructor
// set the game count and initialize the records to be an empty list
if (gameCount <= 0) {
throw new IllegalArgumentException("Must have at least one game!");
}
this.gameCount = gameCount;
// - Throw IllegalArgumentException if gameCount is not positive
// - Use this _exact_ error message for the exception
// (quotes are not part of the message):
// "Must have at least one game!"
}
public int playerCount(){
//report number of players
//O(1)
return records.size(); //default return, remove or update as needed
}
public int gameCount(){
//report number of games
//O(1)
return gameCount; //default return, remove or update as needed
}
public void addPlayer(PlayerRec player){
// append new player into record
// if player is already present, updated the record
// - assume each player has a unique name, i.e. matching names means same player
// O(N) where N is the number of players present
}
public PlayerRec getPlayer(int index){
//return player record corresponding to index
//return null for invalid indexes
if (index < 0 || index >= records.size()) {
return null;
}
return records.get(index);
//O(1)
//default return, remove or update as needed
}
public PlayerRec findPlayer(String name){
//find and return player record with the matching name
//return null if not present
return null;
// O(N) where N is the number of players present
//default return, remove or update as needed
}
public boolean removePlayer(String name){
//remove player with the matching name
//return true if a record is removed successfully; false otherwise
// O(N) where N is the number of players present
return false; //default return, remove or update as needed
}
public boolean changeScore(String name, int game, int newScore){
//set the score of the given game for the player with a matching name
//return false if newScore cannot be set for any reason
// (e.g player /game not present); return true otherwise
// O(N) where N is the number of players present
return false; //default return, remove or update as needed
}
public int topTotalScore(){
//return largest total score among all players
// return -1 if no player present
// O(N) where N is the number of players present
return -3; //default return, remove or update as needed
}
public ThreeTenDynArray
//return the list of players (names only) with the top total score
// if no player present, return an empty list
// if there are multiple players, keep the names in the same order as
// the players in the current record
// O(N) where N is the number of players present
// _if_ appending to the list to return is O(1)
return null; //default return, remove or update as needed
}
public ThreeTenDynArray
// return all scores for the given game index as a list
// - if multiple players are present, keep scores in the same order as
// order of players in records
// - return an empty list if no players present or game index is invalid
// O(M) where M is the number of players
// _if_ appending to the list to return is O(1)
return null; //default return, remove or update as needed
}
public int getGameTotal(int game){
// return the sum of all players' scores of the given game
// - return -1 if no players present or game index is invalid
// O(M) where M is the number of players
return -10; //default return, remove or update as needed
}
public int getGameMax(int game){
// return the max score of the given game
// - return -1 if no players present or game index is invalid
// O(M) where M is the number of players
return -10; //default return, remove or update as needed
}
public int getGameMin(int game){
// return the min score of the given game
// - return -1 if no players present or game index is invalid
// O(M) where M is the number of players
return -10; //default return, remove or update as needed
}
public boolean combine(ScoreBoard another, boolean append){
// add records from another scoreboard into the current one
// - if a player is already present, update the record
// - otherwise,
// -if append is false, records from another should be added
// to the start of the current records but keep their original order
// -if append is true, add new records to the end of the list
// Check main() below and description document for examples.
// return false if two score boards cannot be combined (game count mismatch etc.);
// return true otherwise
// Although we do not have a big-O requirement for this method, you should
// practice code reuse and utilize existing operations as much as possible.
return false; //default return, remove or update as needed
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
