diff --git a/src/main/java/com/booleanuk/core/Exercise.java b/src/main/java/com/booleanuk/core/Exercise.java index e1485c3..78dfbd6 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.security.cert.CRLReason; import java.util.ArrayList; import java.util.HashMap; @@ -48,7 +49,12 @@ public HashMap createPerson() { in the createPerson method */ + public String getValue(String s){ + HashMap map = new HashMap<>(); + map = createPerson(); + return map.get(s); + } /* TODO: 2. Create a method named hasKey that accepts two parameters: @@ -57,7 +63,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 s){ + return map.containsKey(s); + } /* @@ -67,7 +75,11 @@ 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 s){ + if(map.get(s)!=null) return map.get(s); + return -1; + } /* @@ -90,12 +102,19 @@ public ArrayList buildSecretPhrase(ArrayList numbers) { map.put(96, "nice"); // Write your code below this comment... + 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))); + } + } // ...and above this comment // Change the return statement below to return your actual ArrayList - return new ArrayList(); + return list; } }