Skip to content

Commit abef2b0

Browse files
committed
completed
1 parent e19b26f commit abef2b0

File tree

2 files changed

+69
-3
lines changed

2 files changed

+69
-3
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,28 @@ public Exercise(int age) {
5252
provided to the name and age members
5353
*/
5454

55-
55+
public Exercise(String s, int i) {
56+
this.name = s;
57+
this.age = i;
58+
}
5659

5760
/*
5861
2. Create a method named add that accepts two integers. The method should return the numbers added together.
5962
*/
63+
64+
public int add(int a, int b){
65+
int number;
66+
return number = a + b;
67+
}
6068

6169

6270

6371
/*
6472
3. Create another method named add that accepts two Strings. The method should return the strings concatenated
6573
together with a space in between.
6674
*/
67-
68-
75+
public String add (String a, String b) {
76+
return a + " " + b;
77+
}
6978

7079
}

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,63 @@ public class Extension extends ExtensionBase {
2525
E.g.
2626
multiply(["2", "7", "3"], 3) -> [6, 21, 9]
2727
*/
28+
public float add(float a, float b) {
29+
return a + b;
30+
}
2831

32+
public double add (double a, double b){
33+
return a + b;
34+
}
35+
36+
public float subtract(float a, float b) {
37+
return a - b;
38+
}
39+
40+
public String subtract (String a, char b) {
41+
String newString = a.replaceAll(String.valueOf(b), "");
42+
return newString;
43+
}
44+
45+
public int multiply(int a, int b) {
46+
return a * b;
47+
}
48+
49+
public String multiply (String a, int b) {
50+
StringBuilder result = new StringBuilder();
51+
for (int i = 0; i < b; i++) {
52+
result.append(a);
53+
if (i < b - 1) {
54+
result.append(",");
55+
}
56+
}
57+
return result.toString();
58+
}
59+
60+
public int[] multiply (String[] strings, int b) {
61+
int[] newArray = new int[b];
62+
int i = 0;
63+
for (String a : strings){
64+
newArray[i] = (Integer.parseInt(a) * b);
65+
i++;
66+
}
67+
return newArray;
68+
}
2969

3070
}
71+
72+
73+
74+
75+
76+
/*
77+
78+
7. multiply, which accepts an array of Strings that each contain a number, and an int
79+
The method should return an array of ints that contain the value of multiplying each String number by the provided int
80+
E.g.
81+
multiply(["2", "7", "3"], 3) -> [6, 21, 9]*/
82+
83+
84+
85+
86+
87+

0 commit comments

Comments
 (0)