Skip to content

Commit d1ea1c1

Browse files
committed
task complete
1 parent e19b26f commit d1ea1c1

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed

src/main/java/com/booleanuk/core/Exercise.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,27 @@ public Exercise(int age) {
5151
Create a constructor that accepts both a String and an int as parameters, in that order, and assign the values
5252
provided to the name and age members
5353
*/
54-
54+
public Exercise(String name, int age) {
55+
this.name = name;
56+
this.age = age;
57+
}
5558

5659

5760
/*
5861
2. Create a method named add that accepts two integers. The method should return the numbers added together.
5962
*/
60-
63+
public int add(int numOne, int numTwo) {
64+
return numOne + numTwo;
65+
}
6166

6267

6368
/*
6469
3. Create another method named add that accepts two Strings. The method should return the strings concatenated
6570
together with a space in between.
6671
*/
67-
72+
public String add(String stringOne, String stringTwo) {
73+
return stringOne + " " + stringTwo;
74+
}
6875

6976

7077
}

src/main/java/com/booleanuk/extension/Extension.java

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,28 @@
33
import com.booleanuk.helpers.ExtensionBase;
44

55
public class Extension extends ExtensionBase {
6+
7+
public float add(float float1, float float2) {
8+
return float1 + float2;
9+
}
10+
11+
public double add(double d1, double d2) {
12+
return d1 + d2;
13+
}
14+
15+
public float subtract(float f1, float f2) {
16+
return f1-f2;
17+
}
18+
19+
public String subtract(String str, char c) {
20+
String res = "";
21+
for (int i = 0; i < str.length(); i ++) {
22+
if (str.charAt(i) != c) {
23+
res += str.charAt(i);
24+
}
25+
}
26+
return res;
27+
}
628
/*
729
Implement the following methods:
830
@@ -20,11 +42,35 @@ public class Extension extends ExtensionBase {
2042
as many times as the provided int separated by a comma. E.g.
2143
multiply("Hello", 3) -> "Hello,Hello,Hello"
2244
23-
7. multiply, which accepts an array of Strings that each contain a number, and an int
45+
46+
*/
47+
public int multiply(int i1, int i2) {
48+
return i1 * i2;
49+
}
50+
51+
public String multiply(String str, int i) {
52+
String res = str + ",";
53+
while (i > 2) {
54+
res += str + ",";
55+
i --;
56+
}
57+
res += str;
58+
return res;
59+
}
60+
61+
/*
62+
7. multiply, which accepts an array of Strings that each contain a number, and an int
2463
The method should return an array of ints that contain the value of multiplying each String number by the provided int
2564
E.g.
2665
multiply(["2", "7", "3"], 3) -> [6, 21, 9]
2766
*/
67+
public int[] multiply(String[] iString, int factor) {
68+
int[] res = new int[iString.length];
69+
for (int i = 0; i < iString.length; i ++) {
70+
res[i] = Integer.parseInt(iString[i]) * factor;
71+
}
72+
return res;
73+
}
2874

2975

3076
}

0 commit comments

Comments
 (0)