From 8175cfeb8d731f9947baa44f88c7d0a8379deb81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matilda=20S=C3=B6nnergaard?= Date: Tue, 7 Jan 2025 18:39:01 +0100 Subject: [PATCH 1/2] Complete core exercises --- src/main/java/com/booleanuk/core/Exercise.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/booleanuk/core/Exercise.java b/src/main/java/com/booleanuk/core/Exercise.java index 7ac3cfb..ce8a5ef 100644 --- a/src/main/java/com/booleanuk/core/Exercise.java +++ b/src/main/java/com/booleanuk/core/Exercise.java @@ -35,7 +35,7 @@ public String greet(String name) { Complete this method so that it increases the number given by 1 and returns the result */ public int increment(int number) { - return 0; + return ++number; } /* @@ -48,8 +48,8 @@ public int increment(int number) { Nathan | Hi, Nathan :) Edward | Hi, Edward :) */ - public String happilyGreet() { - return "Not implemented yet"; + public String happilyGreet(String name) { + return "Hi, " + name + " :)"; } /* @@ -64,6 +64,15 @@ public String happilyGreet() { 10, 13 | [10,11,12,13] -1, 1 | [-1,0,1] */ + public int[] constructNumberArray(int lower, int upper) { + int[] arr = new int[upper - lower + 1]; + int i = 0; + for (int n=lower; n<=upper; n++) { + arr[i] = n; + i++; + } + return arr; + } @@ -80,6 +89,9 @@ The method must return the same string in upper case with exclamation marks (!) disaster, 5 | DISASTER!!!!! error, 10 | ERROR!!!!!!!!!! */ + public String shout(String s, int n) { + return s.toUpperCase() + "!".repeat(n); + } From d42ede50fab23643d8a8c7d95330b57cf2e74324 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matilda=20S=C3=B6nnergaard?= Date: Tue, 7 Jan 2025 19:02:45 +0100 Subject: [PATCH 2/2] Complete extension exercises --- .../com/booleanuk/extension/Extension.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/booleanuk/extension/Extension.java b/src/main/java/com/booleanuk/extension/Extension.java index f9de7dd..fa81a51 100644 --- a/src/main/java/com/booleanuk/extension/Extension.java +++ b/src/main/java/com/booleanuk/extension/Extension.java @@ -8,9 +8,9 @@ public class Extension extends ExtensionBase { /* 5. Create a method named bakingTime that returns the number 50 */ - - - + public int bakingTime() { + return 50; + } /* 6. Create a method named remainingBakeTime that accepts one input: @@ -19,9 +19,9 @@ public class Extension extends ExtensionBase { It must return how many minutes are left to bake based on the input and the result of calling the bakingTime method */ - - - + public int remainingBakeTime(int nMin) { + return bakingTime() - nMin; + } /* 7. Create a method named calculatePrepTime that accepts one input: @@ -30,9 +30,9 @@ public class Extension extends ExtensionBase { It must return how many minutes it will take to prepare the cake based on each layer taking 3 minutes to prepare */ - - - + public int calculatePrepTime(int nLayers) { + return nLayers * 3; + } /* 8. Create a method named totalTimeSpent that accepts two inputs in this order: @@ -43,8 +43,8 @@ public class Extension extends ExtensionBase { which is the sum of the preparation time and the number of minutes it's been in the oven. Use your calculatePrepTime method in the calculation */ - - - + public int totalTimeSpent(int nLayers, int nMinutes) { + return calculatePrepTime(nLayers) + nMinutes; + } }