Skip to content

Commit 35ca575

Browse files
author
Jonas Finborud Nyman
committed
Completed Exercises and Extensions
1 parent e19b26f commit 35ca575

File tree

2 files changed

+50
-7
lines changed

2 files changed

+50
-7
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,22 @@ 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-
54+
public Exercise(String name, int age) {this.name = name; this.age = age;}
5555

5656

5757
/*
5858
2. Create a method named add that accepts two integers. The method should return the numbers added together.
5959
*/
60-
60+
public int add(int one, int two) {
61+
return one + two;
62+
}
6163

6264

6365
/*
6466
3. Create another method named add that accepts two Strings. The method should return the strings concatenated
6567
together with a space in between.
6668
*/
67-
68-
69-
70-
}
69+
public String add(String one, String two) {
70+
return one + " " + two;
71+
}
72+
}

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

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

32+
public double add(double one, double two) {
33+
return one + two;
34+
}
2935

30-
}
36+
public float subtract(float one, float two) {
37+
return one - two;
38+
}
39+
40+
public String subtract(String str, char letter) {
41+
String newStr = "";
42+
for(int i = 0; i < str.length(); i++) {
43+
if(str.charAt(i) != letter) {
44+
newStr += str.charAt(i);
45+
}
46+
}
47+
return newStr;
48+
}
49+
50+
public int multiply(int one, int two) {
51+
return one * two;
52+
}
53+
54+
public String multiply(String str, int num) {
55+
String newStr = "";
56+
for(int i = 0; i < num; i++) {
57+
newStr += str;
58+
if(i != num - 1)
59+
newStr += ",";
60+
}
61+
return newStr;
62+
}
63+
64+
public int[] multiply(String[] num, int acc) {
65+
int[] newNums = new int[num.length];
66+
for(int i = 0; i < num.length; i++) {
67+
newNums[i] = Integer.parseInt(num[i]) * acc;
68+
}
69+
return newNums;
70+
}
71+
}

0 commit comments

Comments
 (0)