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 stringOne, String stringTwo) {
return stringOne + " " + stringTwo;
}


}
54 changes: 54 additions & 0 deletions src/main/java/com/booleanuk/extension/Extension.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.booleanuk.helpers.ExtensionBase;

import java.util.ArrayList;

public class Extension extends ExtensionBase {
/*
Implement the following methods:
Expand All @@ -25,6 +27,58 @@ public class Extension extends ExtensionBase {
E.g.
multiply(["2", "7", "3"], 3) -> [6, 21, 9]
*/
public float add(float floatOne, float floatTwo) {
return floatOne + floatTwo;
}

public double add(double doubleOne, double doubleTwo) {
return doubleOne + doubleTwo;
}

public float subtract(float floatOne, float floatTwo) {
return floatOne - floatTwo;
}

public String subtract(String string, char character) {
String newString = "";
for (char c : string.toCharArray())
if (c != character) {
newString += c;
}

return newString;
}

public int multiply(int intOne, int intTwo) {
return intOne * intTwo;
}

// 6. multiply, which accepts a string and an int, and returns a string containing the provided string
// as many times as the provided int separated by a comma. E.g.
// multiply("Hello", 3) -> "Hello,Hello,Hello"

public String multiply (String string, int number) {
String newString = "";

for (int i = 0; i < number; i++) {
newString += (string + ",");
}

return newString.substring(0,newString.length()-1);

}
//denna
public int[] multiply(String[] stringArray, int number) {

int[] intArray = new int[stringArray.length];

for (int i = 0; i < stringArray.length; i++) {
int parsedNumber = Integer.parseInt(stringArray[i]);
parsedNumber *= number;
intArray[i] = parsedNumber;
}
return intArray;

}

}
Loading