Skip to content

Thomas Nielsen #114

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 1 commit 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
30 changes: 27 additions & 3 deletions src/main/java/com/booleanuk/core/Exercise.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public HashMap<String, String> createPerson() {
in the createPerson method
*/

public String getValue(String key){
HashMap<String,String> personMap=createPerson();
return personMap.get(key);
}



/*
Expand All @@ -58,7 +63,9 @@ public HashMap<String, String> createPerson() {
in the provided HashMap
*/


public boolean hasKey(HashMap<String,String> hMap, String key){
return hMap.get(key)!=null;
}

/*
TODO: 3. Create a method named getValueOrDefault that accepts two parameters:
Expand All @@ -67,7 +74,14 @@ 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> hMap, String key){
if (hMap.get(key)!=null){
return hMap.get(key);
}
else{
return -1;
}
}


/*
Expand All @@ -89,13 +103,23 @@ public ArrayList<String> buildSecretPhrase(ArrayList<Integer> numbers) {
map.put(7, "muse");
map.put(96, "nice");
// Write your code below this comment...
ArrayList<String> passCode=new ArrayList<>();
for (int i=0; i<numbers.size(); i++){
if (map.get(numbers.get(i))!=null){
passCode.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 passCode;
}
}