Skip to content

Commit

Permalink
Changing define map to getHighScores
Browse files Browse the repository at this point in the history
  • Loading branch information
smcg468 committed Apr 30, 2024
1 parent 51903cb commit 0a2f9da
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
8 changes: 4 additions & 4 deletions exercises/concept/arcade-high-score/.docs/hints.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

- A [map][maps] is an associative data structure of key-value pairs.

## 1. Define a new high score map
## 1. Get all Highscores

- It should return an empty [map][maps].
- [Create an object][create-object] of the HashMap class using the declared `Map<String ,Integer> highScores`.
- It should return a [map][maps] with all the players and their scores.
- [Create an object][create-object] of the HashMap class using the declared `Map<String ,Integer> highScores` to initialise the map.

## 2. Add players to the high score map

Expand All @@ -29,7 +29,7 @@
- The resulting map should be returned with the player's updated score.
- One of the [built-in functions][map-get-or-default] can be used to get a value in a map under a given key if the key is present and update the value, or add the key with a default value if it is not present..

## 6. Get a list of players
## 6. Get all players

- One of the [built-in functions][map-keys] returns a set of all keys in a map.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void updateScore (String name, Integer score) {
highScores.put(name, oldScore + score);
}

Set<String> listOfPlayers () {
Set<String> getPlayers () {
return highScores.keySet();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import java.util.Map;
import java.util.Set;

public class ArcadeHighScore {
class ArcadeHighScore {

Map<String, Integer> highScores;
Map<String, Integer> highScores = new HashMap<>();

Map<String, Integer> defineMap(){
Map<String, Integer> getHighScores(){
throw new UnsupportedOperationException("Please initialise the ArcadeHighScore.highScores map");
}

Expand All @@ -26,7 +26,7 @@ Map<String, Integer> updateScore (String name, Integer score) {
throw new UnsupportedOperationException("Please implement the ArcadeHighScore.updateScore(name, score) method");
}

Set<String> listOfPlayers () {
Set<String> getPlayers () {
throw new UnsupportedOperationException("Please implement the ArcadeHighScore.listOfPlayers() method");
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import org.assertj.core.api.Assert;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Tag;
Expand All @@ -19,8 +18,8 @@ public void setUp() {
@Test
@Tag("task:1")
@DisplayName("Define an empty map to store the high scores")
public void defineMap() {
assertNotNull(arcadeHighScore.defineMap());
public void getHighScores() {
assertNotNull(arcadeHighScore.getHighScores());
assertThat(arcadeHighScore.highScores.isEmpty());
}

Expand Down Expand Up @@ -94,8 +93,8 @@ public void updateScoreOfNonExistentPlayer() {

@Test
@Tag("task:6")
@DisplayName("Get a list of players")
public void listOfPlayers() {
@DisplayName("Get all players")
public void getPlayers() {
String name = "David James";
Integer score = 67;

Expand All @@ -105,6 +104,6 @@ public void listOfPlayers() {
arcadeHighScore.addPlayer(name, score);
arcadeHighScore.addPlayer(secondName, secondScore);

assertThat(arcadeHighScore.listOfPlayers()).contains(name).contains(secondName);
assertThat(arcadeHighScore.getPlayers()).contains(name).contains(secondName);
}
}

0 comments on commit 0a2f9da

Please sign in to comment.