diff --git a/src/main/java/com/booleanuk/core/Exercise.java b/src/main/java/com/booleanuk/core/Exercise.java index 7987028..91341a6 100644 --- a/src/main/java/com/booleanuk/core/Exercise.java +++ b/src/main/java/com/booleanuk/core/Exercise.java @@ -52,19 +52,22 @@ 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 num1, int num2) { + return num1 + num2; + } /* 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 str1, String str2) { + return str1 + " " + str2; + } } diff --git a/src/main/java/com/booleanuk/extension/Extension.java b/src/main/java/com/booleanuk/extension/Extension.java index 62b878f..e0acbf1 100644 --- a/src/main/java/com/booleanuk/extension/Extension.java +++ b/src/main/java/com/booleanuk/extension/Extension.java @@ -26,5 +26,57 @@ public class Extension extends ExtensionBase { multiply(["2", "7", "3"], 3) -> [6, 21, 9] */ + // 1. + public float add(float a, float b) { + return a + b; + } + // 2. + public double add(double a, double b) { + return a + b; + } + + // 3. + public float subtract(float a, float b) { + return a - b; + } + + public String subtract(String a, char b) { + String str = ""; + int length = a.length(); + + for (int i = 0; i < length; i++) { + if (a.charAt(i) != b) { + str += a.charAt(i); + } + } + return str; + } + + public int multiply(int a, int b) { + return a * b; + } + + public String multiply(String a, int b) { + String string = ""; + for (int i = 0; i < b; i++) { + string += a; + if (i < b - 1) { + string += ","; + } + } + return string; + } + + public int[] multiply(String[] a, int b) { + int length = a.length; + int[] newArr = new int[length]; + + for (int i = 0; i < a.length; i++) { + int num = Integer.parseInt(a[i]); + newArr[i] = num*b; + } + return newArr; + } } +