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
26 changes: 25 additions & 1 deletion 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) {
HashMap<String, String> map = createPerson();
return map.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 @@ -67,6 +74,15 @@ 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 str) {
if (map.containsKey(str)) {
int value = map.get(str);
System.out.println(value);
return value;
} else {
return -1;
}
}



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

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

for (int i = 0; i < numbers.size(); i++) {
int key = numbers.get(i);

if (map.containsKey(key)) {
String value = map.get(key);
lst.add(value);
}
}

// ...and above this comment

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