AP Computer Science: Quiz on Designing Classes – The BowlScores Class

 

A BowlScores object keeps track of a bowler’s name, number of games bowled and the scores for those games. The handling of this data will be as follows.

 

Data Members

private String name; // name of the bowler

private int numGames; // the number of games bowled

private int[] gameScores; // list of scores for the bowler

 

 

Write the entire class as described below on your own paper. Pay close attention to each header and be sure to declare all necessary local variables within each method.

 

Constructor

public BowlScores(String nm, int nGames)

// Sets name to nm, numGames to nGames and sizes the array to nGames

 

Accessor Methods

public String getName()

// Returns the name of the bowler

 

public int getNumGames()

// Returns the number of games stored in the object

 

public int[] getBowlScores()

// Returns an array containing all of the bowling scores

 

public int getScore(int n)

// Returns bowling score n from gameScores

                           

public int getTotal()

// Returns the total of all scores in gameScores

 

public double getAverage()

// Returns the average of all scores in gameScores

 

Modifier Methods

public void setName(String nm)

// Sets the name to the value in String nm

 

public void setGameScore(int gameNum, int newScore)

// Sets game gameNum in gameScores to the score newScore

 

Additional Method

public String toString()

// Returns a String containing the object’s data

// The result should be as shown in the example below

 

Bowler: Chuck

Game 1: 178

Game 2: 192

Game 3: 185

Game 4: 183

Total: 738

Average: 184.5