Practice Test 2 Part II (Dragged)
Practice Test 2 Part II (Dragged)
Scores will be
represented as objects of the following ScoreInfo class. Each ScoreInfo object contains a score value
and the number of students who earned that score.
/** Records a score in the database, keeping the database in increasing score order. If no other
* ScoreInfo object represents score, a new ScoreInfo object representing score
* is added to the database; otherwise, the frequency in the ScoreInfo object representing
* score is incremented.
* @param score a score to be recorded in the list
* @return true if a new ScoreInfo object representing score was added to the list;
* false otherwise
*/
public boolean record(int score)
{ /* to be implemented in part (a) */}
/** Records all scores in stuScores in the database, keeping the database in increasing score order
* @param stuScores an array of student test scores
*/
public void recordScores(int[] stuScores)
{ /* to be implemented in part (b) */ }
// There may be instance variables, constructors, and methods that are not shown.
}
(a) Write the Stats method record that takes a test score and records that score in the database. If the
score already exists in the database, the frequency of that score is updated. If the score does not exist in the
database, a new ScoreInfo object is created and inserted in the appropriate position so that the database
is maintained in increasing score order. The method returns true if a new ScoreInfo object was
added to the database; otherwise, it returns false.
Complete method record below.
/** Records a score in the database, keeping the database in increasing score order. If no other
* ScoreInfo object represents score, a new ScoreInfo object representing score
* is added to the database; otherwise, the frequency in the ScoreInfo object representing
* score is incremented.
* @param score a score to be recorded in the list
* @return true if a new ScoreInfo object representing score was added to the list;
* false otherwise
*/
public boolean record(int score)
/** Records all scores in stuScores in the database, keeping the database in increasing score order
* @param stuScores an array of student test scores
*/
public void recordScores(int[] stuScores)
STOP
END OF EXAM
-52-