From 23ed9d9858b61f9e31f91d9fabe68d4709b08ff6 Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Tue, 19 Nov 2024 07:19:51 +0000 Subject: [PATCH 1/2] Setting up GitHub Classroom Feedback From cfb8c3f35f3819ffac580d24ec3b5a7f2d48a1c5 Mon Sep 17 00:00:00 2001 From: cla1427 <182035543+ClarisseLa@users.noreply.github.com> Date: Wed, 20 Nov 2024 14:15:48 +1300 Subject: [PATCH 2/2] Maps --- pom.xml | 8 ++++---- .../com/serenitydojo/WhenWorkingWithMaps.java | 20 ++++++++++++++----- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 96d6ad9..6359435 100644 --- a/pom.xml +++ b/pom.xml @@ -13,8 +13,8 @@ UTF-8 - 12 - 12 + 11 + 11 @@ -92,8 +92,8 @@ org.apache.maven.plugins maven-compiler-plugin - 12 - 12 + 11 + 11 diff --git a/src/test/java/com/serenitydojo/WhenWorkingWithMaps.java b/src/test/java/com/serenitydojo/WhenWorkingWithMaps.java index 19e827f..10827b4 100644 --- a/src/test/java/com/serenitydojo/WhenWorkingWithMaps.java +++ b/src/test/java/com/serenitydojo/WhenWorkingWithMaps.java @@ -3,6 +3,7 @@ import com.serenitydojo.model.FoodType; import org.junit.Test; +import java.util.HashMap; import java.util.Map; import static com.serenitydojo.model.FoodType.*; @@ -22,7 +23,12 @@ public class WhenWorkingWithMaps { // Maps let you associate a value with some other value @Test public void creatingANewSet() { - Map countryCapitals = null; + Map countryCapitals = new HashMap<>(); + + countryCapitals.put("UK","London"); + countryCapitals.put("France","Paris"); + countryCapitals.put("Germany","Berlin"); + // TODO: Create a new map and add the following associations: // UK -> London // France -> Paris @@ -36,7 +42,11 @@ public void creatingANewSet() { // maps can work with different types, e.g. enums to strings @Test public void mapWithDifferentTypes() { - Map favoriteFood = null; + Map favoriteFood = new HashMap<>(); + + favoriteFood.put("cat", FoodType.TUNA); + favoriteFood.put("dog", FoodType.DELUXE_DOG_FOOD); + favoriteFood.put("hamster", FoodType.LETTUCE); // TODO: Create a new map and add the following associations: // "cat" -> TUNA // "dog" -> DELUXE_DOG_FOOD @@ -50,7 +60,7 @@ public void mapWithDifferentTypes() { // We can create a map more easily with the Map.of() method @Test public void usingMapOf() { - Map favoriteFood = null; + Map favoriteFood = Map.of("cat",FoodType.TUNA,"dog",FoodType.DELUXE_DOG_FOOD,"hamster",FoodType.LETTUCE); // TODO: Create a new map and add the following associations using Map.of() // "cat" -> TUNA // "dog" -> DELUXE_DOG_FOOD @@ -71,7 +81,7 @@ public void containsKey() { "hamster", LETTUCE); // TODO: Check that the map contains a key of "dog" - boolean containsDog = false; + boolean containsDog = favoriteFood.containsKey("dog"); assertThat(containsDog).isTrue(); } @@ -85,7 +95,7 @@ public void containsValue() { "hamster", LETTUCE); // TODO: Check that the map contains a value of TUNA - boolean containsTuna = false; + boolean containsTuna = favoriteFood.containsValue(TUNA); assertThat(containsTuna).isTrue(); }