From 0a2f9da5574b7bb29092b74445ee84f3a92e03ac Mon Sep 17 00:00:00 2001 From: Sean Mc Garry Date: Tue, 30 Apr 2024 19:42:03 +0100 Subject: [PATCH] Changing define map to getHighScores --- exercises/concept/arcade-high-score/.docs/hints.md | 8 ++++---- .../.meta/src/reference/java/ArcadeHighScore.java | 2 +- .../src/main/java/ArcadeHighScore.java | 8 ++++---- .../src/test/java/ArcadeHighScoreTest.java | 11 +++++------ 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/exercises/concept/arcade-high-score/.docs/hints.md b/exercises/concept/arcade-high-score/.docs/hints.md index d706296ad..45f35668f 100644 --- a/exercises/concept/arcade-high-score/.docs/hints.md +++ b/exercises/concept/arcade-high-score/.docs/hints.md @@ -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 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 highScores` to initialise the map. ## 2. Add players to the high score map @@ -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. diff --git a/exercises/concept/arcade-high-score/.meta/src/reference/java/ArcadeHighScore.java b/exercises/concept/arcade-high-score/.meta/src/reference/java/ArcadeHighScore.java index db2b21471..110eacfe4 100644 --- a/exercises/concept/arcade-high-score/.meta/src/reference/java/ArcadeHighScore.java +++ b/exercises/concept/arcade-high-score/.meta/src/reference/java/ArcadeHighScore.java @@ -33,7 +33,7 @@ void updateScore (String name, Integer score) { highScores.put(name, oldScore + score); } - Set listOfPlayers () { + Set getPlayers () { return highScores.keySet(); } } diff --git a/exercises/concept/arcade-high-score/src/main/java/ArcadeHighScore.java b/exercises/concept/arcade-high-score/src/main/java/ArcadeHighScore.java index cbfc3623c..9e5e6ded1 100644 --- a/exercises/concept/arcade-high-score/src/main/java/ArcadeHighScore.java +++ b/exercises/concept/arcade-high-score/src/main/java/ArcadeHighScore.java @@ -2,11 +2,11 @@ import java.util.Map; import java.util.Set; -public class ArcadeHighScore { +class ArcadeHighScore { - Map highScores; + Map highScores = new HashMap<>(); - Map defineMap(){ + Map getHighScores(){ throw new UnsupportedOperationException("Please initialise the ArcadeHighScore.highScores map"); } @@ -26,7 +26,7 @@ Map updateScore (String name, Integer score) { throw new UnsupportedOperationException("Please implement the ArcadeHighScore.updateScore(name, score) method"); } - Set listOfPlayers () { + Set getPlayers () { throw new UnsupportedOperationException("Please implement the ArcadeHighScore.listOfPlayers() method"); } } diff --git a/exercises/concept/arcade-high-score/src/test/java/ArcadeHighScoreTest.java b/exercises/concept/arcade-high-score/src/test/java/ArcadeHighScoreTest.java index 827ba48e6..77c8a3d16 100644 --- a/exercises/concept/arcade-high-score/src/test/java/ArcadeHighScoreTest.java +++ b/exercises/concept/arcade-high-score/src/test/java/ArcadeHighScoreTest.java @@ -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; @@ -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()); } @@ -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; @@ -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); } }