diff --git a/src/main/java/com/booleanuk/core/Exercise.java b/src/main/java/com/booleanuk/core/Exercise.java index e1485c3..f93692d 100644 --- a/src/main/java/com/booleanuk/core/Exercise.java +++ b/src/main/java/com/booleanuk/core/Exercise.java @@ -47,6 +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 key) { + return createPerson().get(key); + } @@ -57,6 +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 +73,10 @@ 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) { + int test = map.getOrDefault(string, -1); + return test; + } /* @@ -90,12 +99,15 @@ public ArrayList buildSecretPhrase(ArrayList numbers) { map.put(96, "nice"); // Write your code below this comment... - - + ArrayList newList = new ArrayList<>(); + for (int item : numbers) { + if (map.containsKey(item)) + newList.add(map.get(item)); + } // ...and above this comment // Change the return statement below to return your actual ArrayList - return new ArrayList(); + return newList; } }