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
20 changes: 16 additions & 4 deletions src/main/java/com/booleanuk/core/Exercise.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public HashMap<String, String> 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);
}



Expand All @@ -57,6 +60,9 @@ public HashMap<String, String> 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<String, String> map, String string) {
return map.containsKey(string);
}



Expand All @@ -67,7 +73,10 @@ public HashMap<String, String> 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<String, Integer> map, String string) {
int test = map.getOrDefault(string, -1);
return test;
}


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



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