From eae68e51b6c9e1a01aa1e5fea2be6acb5aaf89a7 Mon Sep 17 00:00:00 2001 From: Robin Kaga Date: Wed, 8 Jan 2025 11:11:32 +0100 Subject: [PATCH] Robin Kaga --- .../java/com/booleanuk/core/Exercise.java | 10 +++++ .../com/booleanuk/extension/Extension.java | 39 +++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/src/main/java/com/booleanuk/core/Exercise.java b/src/main/java/com/booleanuk/core/Exercise.java index 7987028..bfc45c1 100644 --- a/src/main/java/com/booleanuk/core/Exercise.java +++ b/src/main/java/com/booleanuk/core/Exercise.java @@ -51,12 +51,19 @@ public Exercise(int age) { Create a constructor that accepts both a String and an int as parameters, in that order, and assign the values 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 num1, int num2){ + return num1 + num2; + } @@ -64,6 +71,9 @@ public Exercise(int age) { 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 s1, String s2){ + return s1 + " " + s2; + } diff --git a/src/main/java/com/booleanuk/extension/Extension.java b/src/main/java/com/booleanuk/extension/Extension.java index 62b878f..0fe4b84 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 f1, float f2){ + return f1 + f2; + } + + public double add(double d1, double d2){ + return d1 + d2; + } + + public float subtract(float f1, float f2){ + return f1 - f2; + } + + public String subtract(String s, char c){ + String charToString = Character.toString(c); + return s.replaceAll(charToString, ""); + } + + public int multiply(int num1, int num2){ + return num1 * num2; + } + + public String multiply(String s, int num){ + String temp = s; + for (int i = 1; i < num; i++){ + s += "," + temp; + } + + return s; + } + + public int[] multiply(String[] nums, int num){ + int[] ints = new int[nums.length]; + for (int i = 0; i < nums.length; i++){ + int number = Integer.parseInt(nums[i]); + ints[i] = number * num; + } + return ints; + } + }