.java to the src folderYour intelij project directory should look something like the following:
.
lab10
|-- out
`-- src
|-- GameScoreTester.java
|-- LeaderBoard.java
`-- LeaderBoardTester.jav
CreateGameScore.java in the src folder
The game score class will represent a single item in a classic video-game score board:
example of a video-game score board
The first thing you’ll want to do is make a GameScore class. This should have 3 private instance variables:
Implement the following methods:
public GameScore(String name, double score, boolean hardMode) a constructor for this class.public String getName() getter for the name propertypublic double getScore() getter for the score propertypublic boolean isHardMode() getter for the hardMode flag – returns true if the game was hardmode.public String toString()public boolean equals(Object o)Your final task with this class is to make it Comparable. To begin, update the class declaration as follows:
public class GameScore implements Comparable<GameScore>
You should begin by writing the three easy methods:
public int getSize() get the size of the leaderboard.public T highScore() get the largest value in the leaderboardpublic T lowScore() get the smallest value in the leaderboardAll three of these methods should be easy 1-line methods which run in time \(O(1)\).
Key Rules:
/**
* Calculates the average of an array of test scores.
* Returns 0 if the array is null or empty.
*
* @param scores an array of test scores, each in the range [0, 100]
* @param count the number of scores in the array
* @return the average of all scores, or 0 if the array is null or empty
* @throws IllegalArgumentException if count is negative
*
* @author Adriana Picoral
* @version 1.0
*/
public double calculateAverage(double[] scores, int count) {
if (scores == null || scores.length == 0) return 0;
if (count < 0) throw new IllegalArgumentException("Count cannot be negative");
double sum = 0;
for (double score : scores) {
sum += score;
}
return sum / count;
}