Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/main/java/com/booleanuk/core/Exercise.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public HashMap<String, String> createPerson() {
in the createPerson method
*/


public String getValue(String key) { return createPerson().get(key);}

/*
TODO: 2. Create a method named hasKey that accepts two parameters:
Expand All @@ -58,7 +58,7 @@ public HashMap<String, String> createPerson() {
in the provided HashMap
*/


public boolean hasKey(HashMap<String, String> map, String key) { return map.containsKey(key);}

/*
TODO: 3. Create a method named getValueOrDefault that accepts two parameters:
Expand All @@ -68,7 +68,11 @@ public HashMap<String, String> createPerson() {
or -1 if the string provided is not a key in the HashMap
*/


public int getValueOrDefault(HashMap<String, Integer> map, String key) {
if (map.containsKey(key))
return map.get(key);
return -1;
}

/*
TODO: 4. Complete the method below
Expand All @@ -90,12 +94,17 @@ public ArrayList<String> buildSecretPhrase(ArrayList<Integer> numbers) {
map.put(96, "nice");
// Write your code below this comment...

ArrayList<String> phrase = new ArrayList<>();

for(Integer num: numbers){
if (map.containsKey(num))
phrase.add(map.get(num));
}


// ...and above this comment

// Change the return statement below to return your actual ArrayList
return new ArrayList<String>();
return phrase;
}
}
Loading