Skip to content

Commit 0fd6898

Browse files
Completed Excercise
1 parent 5510af5 commit 0fd6898

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/main/java/com/booleanuk/core/Exercise.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import java.util.ArrayList;
66
import java.util.HashMap;
7+
import java.util.List;
78

89
public class Exercise extends ExerciseBase {
910
/*
@@ -48,7 +49,9 @@ public HashMap<String, String> createPerson() {
4849
in the createPerson method
4950
*/
5051

51-
52+
public String getValue(String key) {
53+
return createPerson().get(key);
54+
}
5255

5356
/*
5457
TODO: 2. Create a method named hasKey that accepts two parameters:
@@ -58,7 +61,10 @@ public HashMap<String, String> createPerson() {
5861
in the provided HashMap
5962
*/
6063

64+
public boolean hasKey(HashMap<String, String> map, String key) {
6165

66+
return map.containsKey(key);
67+
}
6268

6369
/*
6470
TODO: 3. Create a method named getValueOrDefault that accepts two parameters:
@@ -68,6 +74,12 @@ public HashMap<String, String> createPerson() {
6874
or -1 if the string provided is not a key in the HashMap
6975
*/
7076

77+
public int getValueOrDefault(HashMap<String, Integer> map, String key){
78+
if(map.get(key)!=null)
79+
return map.get(key);
80+
else
81+
return -1;
82+
}
7183

7284

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

93-
94-
105+
ArrayList<String> liste = new ArrayList<>();
106+
for (int i = 0; i < numbers.size() ; i++) {
107+
if(map.get(numbers.get(i))!=null)
108+
liste.add(map.get(numbers.get(i)));
109+
}
95110

96111
// ...and above this comment
97112

98113
// Change the return statement below to return your actual ArrayList
99-
return new ArrayList<String>();
114+
return liste;
100115
}
101116
}

0 commit comments

Comments
 (0)