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 numOne, int numTwo){
return numOne+numTwo;
}



/*
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 strOne, String strTwo){
return strOne + " " + strTwo;
}

}
36 changes: 36 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,42 @@ public class Extension extends ExtensionBase {
E.g.
multiply(["2", "7", "3"], 3) -> [6, 21, 9]
*/
public float add(float flOne, float flTwo){
return flOne + flTwo;
}

public double add(double dblOne, double dblTwo){
return dblOne + dblTwo;
}

public float subtract(float flOne, float flTwo){
return flOne - flTwo;
}

public String subtract(String str, char ch){
return str.replace(Character.toString(ch), "");
}

public int multiply(int numOne, int numTwo){
return numOne * numTwo;
}

public String multiply(String str, int num){
String sequence = str;
for (int i = 1; i<num; i++){
sequence = sequence + "," + str;
}
return sequence;
}

public int[] multiply(String[] strarr, int num){
int[] result = new int[strarr.length];
int temp;
for(int i = 0; i<strarr.length; i++){
temp = Integer.parseInt(strarr[i]);
temp=temp*num;
result[i]=temp;
}
return result;
}
}
2 changes: 1 addition & 1 deletion src/test/java/com/booleanuk/extension/ExtensionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ public void shouldMultiplyArray() {

Assertions.assertArrayEquals(result, this.extension.multiply(nums, 3));
}
}
}
Loading