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
34 changes: 30 additions & 4 deletions src/main/java/com/booleanuk/core/Exercise.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public HashMap<String, String> createPerson() {
in the createPerson method
*/

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



/*
Expand All @@ -58,6 +62,9 @@ public HashMap<String, String> createPerson() {
in the provided HashMap
*/

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


/*
Expand All @@ -68,7 +75,9 @@ 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 str){
return map.getOrDefault(str, -1);
}

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



ArrayList<String> 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<String>();
return ans;
}
}













Loading