Skip to content

Commit 6dcc64a

Browse files
committed
Solved tasks
1 parent e19b26f commit 6dcc64a

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,28 @@ 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+
}
5458

5559

5660

5761
/*
5862
2. Create a method named add that accepts two integers. The method should return the numbers added together.
5963
*/
60-
64+
public int add(int int1, int int2) {
65+
return int1 + int2;
66+
}
6167

6268

6369
/*
6470
3. Create another method named add that accepts two Strings. The method should return the strings concatenated
6571
together with a space in between.
6672
*/
6773

68-
74+
public String add(String string1, String string2) {
75+
return string1 + " " + string2;
76+
}
6977

7078
}

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.booleanuk.helpers.ExtensionBase;
44

5+
import java.util.ArrayList;
6+
57
public class Extension extends ExtensionBase {
68
/*
79
Implement the following methods:
@@ -26,5 +28,46 @@ public class Extension extends ExtensionBase {
2628
multiply(["2", "7", "3"], 3) -> [6, 21, 9]
2729
*/
2830

31+
public float add(float float1, float float2) {
32+
return float1 + float2;
33+
}
34+
35+
36+
public double add(double double1, double double2) {
37+
return double1 + double2;
38+
}
39+
40+
41+
public float subtract(float float1, float float2) {
42+
return float1 - float2;
43+
}
44+
45+
46+
public String subtract(String string, char character) {
47+
return string.replace(String.valueOf(character), "");
48+
}
49+
50+
51+
public int multiply(int int1, int int2) {
52+
return int1 * int2;
53+
}
54+
55+
56+
public String multiply(String string, int number) {
57+
String output = string;
58+
while (number - 1 != 0) {
59+
number--;
60+
output += "," + string;
61+
}
62+
return output;
63+
}
64+
2965

66+
public int[] multiply(String[] strings, int number) {
67+
int[] results = new int[strings.length];
68+
for (int i = 0; i < strings.length; i++) {
69+
results[i] = Integer.parseInt(strings[i]) * number;
70+
}
71+
return results;
72+
}
3073
}

0 commit comments

Comments
 (0)