Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/main/java/com/booleanuk/core/Exercise.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,28 @@ public Exercise(int age) {
Create a constructor that accepts both a String and an int as parameters, in that order, and assign the values
provided to the name and age members
*/
public Exercise(String name, int age){
this.name = name;
this.age = age;
}



/*
2. Create a method named add that accepts two integers. The method should return the numbers added together.
*/

public int add(int x1, int x2){
return x1+x2;
}


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

public String add(String s1, String s2){
return s1+" "+s2;
}


}
45 changes: 45 additions & 0 deletions src/main/java/com/booleanuk/extension/Extension.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,51 @@ public class Extension extends ExtensionBase {
E.g.
multiply(["2", "7", "3"], 3) -> [6, 21, 9]
*/
public float add(float x1, float x2){
return x1+x2;
}

public double add(double x1, double x2){
return x1+x2;
}

public float subtract(float x1, float x2){
return x1-x2;
}

public String subtract(String string, char character){
String retStr = "";
for(int i = 0; i < string.length(); i++){
char curr = string.charAt(i);
if(curr != character){
retStr += curr;
}
}
return retStr;
}

public int multiply(int x1, int x2){
return x1*x2;
}

public String multiply(String str, int num) {
String retStr = "";
for(int i = 0; i < num; i++) {
retStr += str;

if(i != num-1){
retStr += ",";
}
}
return retStr;
}

public int[] multiply(String[] strs, int mul){
int strLen = strs.length;
int[] retNums = new int[strLen];
for(int i = 0; i < strLen; i++){
retNums[i] = Integer.parseInt(strs[i])*mul;
}
return retNums;
}
}
Loading