diff --git a/src/main/java/com/booleanuk/core/Exercise.java b/src/main/java/com/booleanuk/core/Exercise.java index e1485c3..1cc3474 100644 --- a/src/main/java/com/booleanuk/core/Exercise.java +++ b/src/main/java/com/booleanuk/core/Exercise.java @@ -48,6 +48,9 @@ public HashMap createPerson() { in the createPerson method */ + public String getValue(String key){ + return createPerson().get(key); + } /* @@ -57,7 +60,9 @@ public HashMap createPerson() { The method must return a boolean that represents whether the string provided exists as a key in the provided HashMap */ - + public boolean hasKey(HashMap map, String string){ + return map.containsKey(string); + } /* @@ -67,7 +72,12 @@ public HashMap createPerson() { The method must use the string provided to return the integer contained in the provided HashMap, or -1 if the string provided is not a key in the HashMap */ - + public int getValueOrDefault (HashMap map, String string) { + if(map.get(string) != null){ + return map.get(string); + } + return -1; + } /* @@ -89,13 +99,16 @@ public ArrayList buildSecretPhrase(ArrayList numbers) { map.put(7, "muse"); map.put(96, "nice"); // Write your code below this comment... + ArrayList list = new ArrayList<>(); - - - + for (Integer number : numbers) { + if (map.get(number) != null) { + list.add(map.get(number)); + } + } // ...and above this comment // Change the return statement below to return your actual ArrayList - return new ArrayList(); + return list; } } diff --git a/src/test/java/com/booleanuk/core/ExerciseTest.java b/src/test/java/com/booleanuk/core/ExerciseTest.java index 742475e..d23ef5f 100644 --- a/src/test/java/com/booleanuk/core/ExerciseTest.java +++ b/src/test/java/com/booleanuk/core/ExerciseTest.java @@ -6,7 +6,7 @@ import java.util.ArrayList; import java.util.HashMap; -class ExerciseTest { +class ExerciseTest { Exercise exercise; public ExerciseTest() {