Skip to content

Finished Task 2 Melvin Uthayaseelan #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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: 21 additions & 5 deletions src/main/java/com/booleanuk/core/Exercise.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import java.util.ArrayList;
import java.util.HashMap;

public class Exercise extends ExerciseBase {
/*
The final fundamental building block of Java is a Map. There is still much to learn about the language,
Expand Down Expand Up @@ -48,6 +47,12 @@ public HashMap<String, String> createPerson() {
in the createPerson method
*/

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





/*
Expand All @@ -58,8 +63,10 @@ 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:
- A HashMap of String, Integer key value pairs
Expand All @@ -68,6 +75,10 @@ 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) {
return map.getOrDefault(key, -1);
}



/*
Expand All @@ -88,14 +99,19 @@ public ArrayList<String> buildSecretPhrase(ArrayList<Integer> numbers) {
map.put(6712, "bass");
map.put(7, "muse");
map.put(96, "nice");
// Write your code below this comment...

// Write your code elow this comment...

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

for (Integer number : numbers) {
if (map.containsKey(number)) {
secretPhrase.add(map.get(number));
}
}

// ...and above this comment

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