diff --git a/src/main/java/com/booleanuk/core/Exercise.java b/src/main/java/com/booleanuk/core/Exercise.java index e1485c3..711c867 100644 --- a/src/main/java/com/booleanuk/core/Exercise.java +++ b/src/main/java/com/booleanuk/core/Exercise.java @@ -47,7 +47,9 @@ 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 id) { + return createPerson().get(id); + } /* @@ -57,7 +59,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 id){ + return map.containsKey(id); + } /* @@ -68,7 +72,9 @@ public HashMap createPerson() { or -1 if the string provided is not a key in the HashMap */ - + public int getValueOrDefault(HashMap map, String id) { + return map.getOrDefault(id, -1); + } /* TODO: 4. Complete the method below @@ -89,6 +95,14 @@ public ArrayList buildSecretPhrase(ArrayList numbers) { map.put(7, "muse"); map.put(96, "nice"); // Write your code below this comment... + ArrayList output = new ArrayList<>(); + + for (int i : numbers) { + if (map.containsKey(i)) { + output.add(map.get(i)); + } + } + @@ -96,6 +110,6 @@ public ArrayList buildSecretPhrase(ArrayList numbers) { // ...and above this comment // Change the return statement below to return your actual ArrayList - return new ArrayList(); + return output; } }