From bb6b96b321403369cd9fe23db7ce2f822b0f8c36 Mon Sep 17 00:00:00 2001 From: TMajlu Date: Tue, 13 Aug 2024 13:24:56 +0200 Subject: [PATCH] Did the Core exercises --- .../java/com/booleanuk/core/Exercise.java | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/booleanuk/core/Exercise.java b/src/main/java/com/booleanuk/core/Exercise.java index e1485c3..c0d4add 100644 --- a/src/main/java/com/booleanuk/core/Exercise.java +++ b/src/main/java/com/booleanuk/core/Exercise.java @@ -48,6 +48,11 @@ public HashMap createPerson() { in the createPerson method */ + public String getValue(String key){ + HashMap personMap=createPerson(); + return personMap.get(key); + } + /* @@ -58,7 +63,9 @@ public HashMap createPerson() { in the provided HashMap */ - + public boolean hasKey(HashMap hMap, String key){ + return hMap.get(key)!=null; + } /* TODO: 3. Create a method named getValueOrDefault that accepts two parameters: @@ -67,7 +74,14 @@ public HashMap 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 hMap, String key){ + if (hMap.get(key)!=null){ + return hMap.get(key); + } + else{ + return -1; + } + } /* @@ -89,6 +103,16 @@ public ArrayList buildSecretPhrase(ArrayList numbers) { map.put(7, "muse"); map.put(96, "nice"); // Write your code below this comment... + ArrayList passCode=new ArrayList<>(); + for (int i=0; i buildSecretPhrase(ArrayList numbers) { // ...and above this comment // Change the return statement below to return your actual ArrayList - return new ArrayList(); + return passCode; } }