From b8ac7a67ee83b80c3d9bcf6ce3349e3b17d30346 Mon Sep 17 00:00:00 2001 From: Frida Anselin Date: Mon, 13 Jan 2025 20:13:32 +0100 Subject: [PATCH 1/2] Completed constructors overloading core exercises --- src/main/java/com/booleanuk/core/Exercise.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/booleanuk/core/Exercise.java b/src/main/java/com/booleanuk/core/Exercise.java index 7987028..6ddbdf3 100644 --- a/src/main/java/com/booleanuk/core/Exercise.java +++ b/src/main/java/com/booleanuk/core/Exercise.java @@ -52,19 +52,26 @@ public Exercise(int age) { provided to the name and age members */ - + public Exercise(String name, int age) { + this.name = name; + this.age = age; + } /* 2. Create a method named add that accepts two integers. The method should return the numbers added together. */ - + public int add(int one, int two) { + return one + two; + } /* 3. Create another method named add that accepts two Strings. The method should return the strings concatenated together with a space in between. */ - + public String add(String one, String two) { + return one + " " + two; + } } From 74ec527ad53787802c3e5771f160e3516b4d1741 Mon Sep 17 00:00:00 2001 From: Frida Anselin Date: Mon, 13 Jan 2025 22:59:03 +0100 Subject: [PATCH 2/2] Completed constructors overloading extension exercises --- .../com/booleanuk/extension/Extension.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/main/java/com/booleanuk/extension/Extension.java b/src/main/java/com/booleanuk/extension/Extension.java index 62b878f..2e76cd4 100644 --- a/src/main/java/com/booleanuk/extension/Extension.java +++ b/src/main/java/com/booleanuk/extension/Extension.java @@ -26,5 +26,44 @@ public class Extension extends ExtensionBase { multiply(["2", "7", "3"], 3) -> [6, 21, 9] */ + public float add(float one, float two) { + return one + two; + } + + public double add(double one, double two) { + return one + two; + } + + public float subtract(float one, float two) { + return one - two; + } + + public String subtract(String word, char letter) { + return word.replaceAll(Character.toString(letter), ""); + } + + public int multiply(int one, int two) { + return one * two; + } + + public String multiply(String word, int number) { + StringBuilder output = new StringBuilder(); + for (int i = 0; i < number; i++) { + output.append(word); + if (i < number - 1) { + output.append(","); + } + } + return output.toString(); + } + + public int[] multiply(String[] numbers, int multiplier) { + int[] multiplied = new int[numbers.length]; + for (int i = 0; i < numbers.length; i++) { + int current = Integer.parseInt(numbers[i]); + multiplied[i] = current * multiplier; + } + return multiplied; + } }