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
23 changes: 19 additions & 4 deletions src/main/java/com/booleanuk/core/Exercise.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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

public class Exercise extends ExerciseBase {
/*
Expand Down Expand Up @@ -48,7 +49,9 @@ 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 +61,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:
Expand All @@ -68,6 +74,12 @@ 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.get(key)!=null)
return map.get(key);
else
return -1;
}


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



ArrayList<String> liste = new ArrayList<>();
for (int i = 0; i < numbers.size() ; i++) {
if(map.get(numbers.get(i))!=null)
liste.add(map.get(numbers.get(i)));
}

// ...and above this comment

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