diff --git a/src/main/java/com/booleanuk/core/Exercise.java b/src/main/java/com/booleanuk/core/Exercise.java index e1485c3..5603eba 100644 --- a/src/main/java/com/booleanuk/core/Exercise.java +++ b/src/main/java/com/booleanuk/core/Exercise.java @@ -2,6 +2,7 @@ import com.booleanuk.helpers.ExerciseBase; +import java.lang.reflect.Array; import java.util.ArrayList; import java.util.HashMap; @@ -47,6 +48,10 @@ public HashMap createPerson() { The method must return the value associated to the provided key from the HashMap created in the createPerson method */ + public String getValue(String key) { + HashMap map = createPerson(); + return map.get(key); + } @@ -58,6 +63,10 @@ public HashMap createPerson() { in the provided HashMap */ + public boolean hasKey(HashMap map, String key) { + return map.containsKey(key); + } + /* @@ -68,6 +77,10 @@ public HashMap createPerson() { or -1 if the string provided is not a key in the HashMap */ + public int getValueOrDefault(HashMap map, String key) { + return map.getOrDefault(key, -1); + } + /* @@ -89,13 +102,12 @@ public ArrayList buildSecretPhrase(ArrayList numbers) { map.put(7, "muse"); map.put(96, "nice"); // Write your code below this comment... - - - - - // ...and above this comment - - // Change the return statement below to return your actual ArrayList - return new ArrayList(); + ArrayList list = new ArrayList<>(); + for (int i = 0; i < numbers.size(); i++) { + if (map.containsKey(numbers.get(i))) { + list.add(map.get(numbers.get(i))); + } + } + return list; } }