From c5918be39634624619cbe21a28109d993a6f05ed Mon Sep 17 00:00:00 2001 From: Mattias Hedbom Date: Wed, 8 Jan 2025 21:42:25 +0100 Subject: [PATCH] Methods completed --- .../java/com/booleanuk/core/Exercise.java | 20 +++++++++++++++---- .../com/booleanuk/extension/Extension.java | 15 +++++++++++--- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/booleanuk/core/Exercise.java b/src/main/java/com/booleanuk/core/Exercise.java index 7ac3cfb..5a40469 100644 --- a/src/main/java/com/booleanuk/core/Exercise.java +++ b/src/main/java/com/booleanuk/core/Exercise.java @@ -2,6 +2,8 @@ import com.booleanuk.helpers.ExerciseBase; +import java.util.stream.IntStream; + public class Exercise extends ExerciseBase { /* A method is a function, a single piece of logic that can run. In Java, a class is a convenient @@ -35,7 +37,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+1; } /* @@ -48,8 +50,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,7 +66,11 @@ public String happilyGreet() { 10, 13 | [10,11,12,13] -1, 1 | [-1,0,1] */ + public int[] constructNumberArray(int lower, int upper){ + int[] intArray = IntStream.rangeClosed(lower, upper).toArray(); + return intArray; + } @@ -80,7 +86,13 @@ The method must return the same string in upper case with exclamation marks (!) disaster, 5 | DISASTER!!!!! error, 10 | ERROR!!!!!!!!!! */ - + public String shout(String word, int numExclamationMarks){ + String shoutedWord = word.toUpperCase(); + for(int i = 0; i < numExclamationMarks; i++){ + shoutedWord += "!"; + } + return shoutedWord; + } diff --git a/src/main/java/com/booleanuk/extension/Extension.java b/src/main/java/com/booleanuk/extension/Extension.java index f9de7dd..e64ef55 100644 --- a/src/main/java/com/booleanuk/extension/Extension.java +++ b/src/main/java/com/booleanuk/extension/Extension.java @@ -8,6 +8,9 @@ public class Extension extends ExtensionBase { /* 5. Create a method named bakingTime that returns the number 50 */ + public int bakingTime(){ + return 50; + } @@ -19,7 +22,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 minInOven){ + return bakingTime() - minInOven; + } @@ -30,7 +35,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 numLayers){ + return numLayers*3; + } @@ -43,7 +50,9 @@ 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 numLayers, int minInOven){ + return calculatePrepTime(numLayers) + minInOven; + }