diff --git a/src/main/java/com/booleanuk/core/Exercise.java b/src/main/java/com/booleanuk/core/Exercise.java index d31a45c..2fa9332 100644 --- a/src/main/java/com/booleanuk/core/Exercise.java +++ b/src/main/java/com/booleanuk/core/Exercise.java @@ -3,6 +3,7 @@ import com.booleanuk.helpers.ExerciseBase; import java.util.ArrayList; +import java.util.List; public class Exercise extends ExerciseBase { /* @@ -43,6 +44,9 @@ public ArrayList getFavouriteNumbers() { TODO: 1. Create a method named getSecondNumber that returns a whole number. It must return the second number contained in the list that is returned from getFavouriteNumbers */ + public int getSecondNumber() { + return getFavouriteNumbers().get(1); + } @@ -56,6 +60,10 @@ public ArrayList getFavouriteNumbers() { https://www.programiz.com/java-programming/library/arraylist/replaceall */ + public ArrayList multiply(ArrayList numbers, int number) { + numbers.replaceAll(n -> n * number); + return numbers; + } /* @@ -63,7 +71,9 @@ public ArrayList getFavouriteNumbers() { - A list of strings The method must return a boolean that indicates whether the provided list is empty or not */ - + public boolean isEmpty(ArrayList strings) { + return strings.isEmpty(); + } /* @@ -72,7 +82,10 @@ public ArrayList getFavouriteNumbers() { - A string The method must add the second parameter into the list provided and then return the list */ - + public ArrayList addIngredient(ArrayList strings, String string) { + strings.add(string); + return strings; + } /* @@ -81,7 +94,13 @@ public ArrayList getFavouriteNumbers() { - A string The method must remove the second parameter from the list and then return the list */ - + public ArrayList removeIngredient(ArrayList strings, String string) { + for (String txt : strings) { + if (string.equals(txt)) + strings.remove(txt); + } + return strings; + } /* @@ -90,7 +109,10 @@ public ArrayList getFavouriteNumbers() { - A string The method must return a boolean that indicates whether the second parameter exists in the provided list */ + public boolean containsIngredient(ArrayList strings, String string) { + return strings.contains(string); + } }