Skip to content

Commit eae68e5

Browse files
author
Robin Kaga
committed
Robin Kaga
1 parent e19b26f commit eae68e5

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,29 @@ 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
*/
64+
public int add(int num1, int num2){
65+
return num1 + num2;
66+
}
6067

6168

6269

6370
/*
6471
3. Create another method named add that accepts two Strings. The method should return the strings concatenated
6572
together with a space in between.
6673
*/
74+
public String add(String s1, String s2){
75+
return s1 + " " + s2;
76+
}
6777

6878

6979

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

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

29+
public float add(float f1, float f2){
30+
return f1 + f2;
31+
}
32+
33+
public double add(double d1, double d2){
34+
return d1 + d2;
35+
}
36+
37+
public float subtract(float f1, float f2){
38+
return f1 - f2;
39+
}
40+
41+
public String subtract(String s, char c){
42+
String charToString = Character.toString(c);
43+
return s.replaceAll(charToString, "");
44+
}
45+
46+
public int multiply(int num1, int num2){
47+
return num1 * num2;
48+
}
49+
50+
public String multiply(String s, int num){
51+
String temp = s;
52+
for (int i = 1; i < num; i++){
53+
s += "," + temp;
54+
}
55+
56+
return s;
57+
}
58+
59+
public int[] multiply(String[] nums, int num){
60+
int[] ints = new int[nums.length];
61+
for (int i = 0; i < nums.length; i++){
62+
int number = Integer.parseInt(nums[i]);
63+
ints[i] = number * num;
64+
}
65+
return ints;
66+
}
67+
2968

3069
}

0 commit comments

Comments
 (0)