Skip to content
Closed
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
13 changes: 12 additions & 1 deletion src/main/java/com/booleanuk/core/Exercise.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,31 @@ 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 age1, int age2) {
return age1 + age2;
}


/*
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 name1, String name2) {
return (name1 + " " + name2);
}



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

import com.booleanuk.helpers.ExtensionBase;

import java.util.Arrays;

public class Extension extends ExtensionBase {
/*
Implement the following methods:

1. add, which accepts two floats and returns a float (both floats added together)


2. add, which accepts two doubles and returns a double (both doubles added together)

3. subtract, which accepts two floats and returns a float (first float minus second float)
Expand All @@ -26,5 +29,39 @@ public class Extension extends ExtensionBase {
multiply(["2", "7", "3"], 3) -> [6, 21, 9]
*/

public float add(float f1, float f2) {
return f1 + f2;
}

public double add(double d1, double d2) {
return d1 + d2;
}

public float subtract(float f1, float f2) {
return f1 - f2;
}

public String subtract(String d1, char d2) {
return d1.replace(d2 + "", "");
}

public int multiply(int f1, int f2) {
return f1 * f2;
}

public String multiply(String d1, int d2) {
String returnValue = "";
while (d2 > 1) {
returnValue += d1 + ",";
d2 --;
}
return returnValue + d1;

}

public int[] multiply(String[] d1, int d2) {
return Arrays.stream(d1).mapToInt(x -> Integer.parseInt(x) * d2).toArray();

}

}
Loading