diff --git a/src/main/java/com/booleanuk/core/Exercise.java b/src/main/java/com/booleanuk/core/Exercise.java index e1485c3..66124a8 100644 --- a/src/main/java/com/booleanuk/core/Exercise.java +++ b/src/main/java/com/booleanuk/core/Exercise.java @@ -48,6 +48,10 @@ public HashMap createPerson() { in the createPerson method */ + public String getValue(String key){ + return createPerson().get(key); + } + /* @@ -58,6 +62,9 @@ public HashMap createPerson() { in the provided HashMap */ + public boolean hasKey(HashMap map, String str){ + return map.containsKey(str); + } /* @@ -68,7 +75,9 @@ public HashMap createPerson() { or -1 if the string provided is not a key in the HashMap */ - + public int getValueOrDefault(HashMap map, String str){ + return map.getOrDefault(str, -1); + } /* TODO: 4. Complete the method below @@ -90,12 +99,29 @@ public ArrayList buildSecretPhrase(ArrayList numbers) { map.put(96, "nice"); // Write your code below this comment... - - + ArrayList ans = new ArrayList<>(); + for (int x : numbers){ + if (map.containsKey(x)){ + ans.add(map.get(x)); + } + } // ...and above this comment // Change the return statement below to return your actual ArrayList - return new ArrayList(); + return ans; } } + + + + + + + + + + + + +