Skip to content

Commit d36d112

Browse files
author
Roderick Leito
committed
Finished all ex
1 parent e19b26f commit d36d112

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-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
*/
64+
public int add(int numOne, int numTwo){
65+
return numOne+numTwo;
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
*/
67-
68-
74+
public String add(String strOne, String strTwo){
75+
return strOne + " " + strTwo;
76+
}
6977

7078
}

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

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

32+
public double add(double dblOne, double dblTwo){
33+
return dblOne + dblTwo;
34+
}
2935

36+
public float subtract(float flOne, float flTwo){
37+
return flOne - flTwo;
38+
}
39+
40+
public String subtract(String str, char ch){
41+
return str.replace(Character.toString(ch), "");
42+
}
43+
44+
public int multiply(int numOne, int numTwo){
45+
return numOne * numTwo;
46+
}
47+
48+
public String multiply(String str, int num){
49+
String sequence = str;
50+
for (int i = 1; i<num; i++){
51+
sequence = sequence + "," + str;
52+
}
53+
return sequence;
54+
}
55+
56+
public int[] multiply(String[] strarr, int num){
57+
int[] result = new int[strarr.length];
58+
int temp;
59+
for(int i = 0; i<strarr.length; i++){
60+
temp = Integer.parseInt(strarr[i]);
61+
temp=temp*num;
62+
result[i]=temp;
63+
}
64+
return result;
65+
}
3066
}

0 commit comments

Comments
 (0)