From f9113327f168efa41f067d0b400f47fd7598b81e Mon Sep 17 00:00:00 2001 From: Petros Mylonas Date: Wed, 10 Jan 2024 18:12:31 +0200 Subject: [PATCH 1/2] Petros Mylonas --- .../java/com/booleanuk/core/Exercise.java | 56 +++++++++++++------ 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/booleanuk/core/Exercise.java b/src/main/java/com/booleanuk/core/Exercise.java index 7ac3cfb..90de9d7 100644 --- a/src/main/java/com/booleanuk/core/Exercise.java +++ b/src/main/java/com/booleanuk/core/Exercise.java @@ -35,7 +35,8 @@ 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; + number +=1; + return number; } /* @@ -48,27 +49,42 @@ 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 + " :)"; } - /* - 3. Construct an array of numbers - Create a method named constructNumberArray that accepts two whole numbers named lower and upper. - The method must return an array containing all the whole numbers between lower and upper, - including lower and upper. Example input and output: - - Input | Output - -------|------- - 1, 3 | [1,2,3] - 10, 13 | [10,11,12,13] - -1, 1 | [-1,0,1] - */ + /* + 3. Construct an array of numbers + Create a method named constructNumberArray that accepts two whole numbers named lower and upper. + The method must return an array containing all the whole numbers between lower and upper, + including lower and upper. Example input and output: + + Input | Output + -------|------- + 1, 3 | [1,2,3] + 10, 13 | [10,11,12,13] + -1, 1 | [-1,0,1] + */ + + + ; + + @Override + public int[] constructNumberArray(int lower, int upper) { + int arraySize = upper - lower + 1; + int[] resultArray = new int[arraySize]; + + for (int i = 0; i < arraySize; i++) { + resultArray[i] = lower + i; + } + return resultArray; + } - /* + /* 4. Shout at a dev Create a method named shout that accepts a string and a whole number. The method must return the same string in upper case with exclamation marks (!) appended to the end. @@ -81,7 +97,13 @@ The method must return the same string in upper case with exclamation marks (!) error, 10 | ERROR!!!!!!!!!! */ + public String shout(String w, int num) { + String s = w.toUpperCase() ; + for (int i = 0; i < num; i++) { + s += "!"; + } + return s; + }} -} From c9d58fa2b47411a0cbd312b84a4663dad7a08927 Mon Sep 17 00:00:00 2001 From: Petros Mylonas Date: Thu, 11 Jan 2024 12:15:16 +0200 Subject: [PATCH 2/2] Petros Mylonas --- .../java/com/booleanuk/extension/Extension.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/booleanuk/extension/Extension.java b/src/main/java/com/booleanuk/extension/Extension.java index f9de7dd..668cda1 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; + } @@ -21,6 +24,9 @@ public class Extension extends ExtensionBase { */ + public int remainingBakeTime ( int number){ + return bakingTime()- number; +} /* @@ -30,7 +36,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 layers){ + return layers*3; +} @@ -45,6 +53,7 @@ public class Extension extends ExtensionBase { */ - - + public int totalTimeSpent(int layers, int minutes) { + return calculatePrepTime(layers)+minutes; + } }