Skip to content

Commit cd9d672

Browse files
committed
completed
1 parent e19b26f commit cd9d672

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,30 @@ 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+
public Exercise(String name, int age) {
55+
this.name = name;
56+
this.age = age;
57+
}
58+
5459

5560

5661

5762
/*
5863
2. Create a method named add that accepts two integers. The method should return the numbers added together.
5964
*/
65+
public int add(int a, int b) {
66+
return 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
*/
75+
public String add(String a, String b) {
76+
return a + " " + b;
77+
}
6778

6879

6980

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,41 @@ public class Extension extends ExtensionBase {
2626
multiply(["2", "7", "3"], 3) -> [6, 21, 9]
2727
*/
2828

29+
public float add(float a, float b) {
30+
return a + b;
31+
}
2932

33+
public double add(double a, double b) {
34+
return a + b;
35+
}
36+
37+
public float subtract(float a, float b) {
38+
return a - b;
39+
}
40+
41+
public String subtract(String s, char c) {
42+
return s.replace(""+c,"");
43+
}
44+
45+
public int multiply(int a, int b) {
46+
return a * b;
47+
}
48+
49+
public String multiply(String s, int n) {
50+
String res = s;
51+
for (int i = 0; i < n - 1; i++) {
52+
res += "," + s;
53+
}
54+
return res;
55+
}
56+
57+
public int[] multiply(String[] nums, int n) {
58+
int[] result = new int[nums.length];
59+
60+
for (int i = 0; i < nums.length; i++) {
61+
result[i] = Integer.parseInt(nums[i]) * n;
62+
}
63+
64+
return result;
65+
}
3066
}

0 commit comments

Comments
 (0)