diff --git a/src/main/java/com/booleanuk/core/Exercise.java b/src/main/java/com/booleanuk/core/Exercise.java index d31a45c..c71f1be 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 { /* @@ -44,7 +45,10 @@ public ArrayList getFavouriteNumbers() { second number contained in the list that is returned from getFavouriteNumbers */ - + public int getSecondNumber() { + List numbers = getFavouriteNumbers(); + return numbers.get(1); + } /* TODO: 2. Create a method named multiply that accepts two parameters in this order: @@ -56,7 +60,10 @@ public ArrayList getFavouriteNumbers() { https://www.programiz.com/java-programming/library/arraylist/replaceall */ - + public ArrayList multiply(ArrayList numbersList, int number) { + numbersList.replaceAll(e -> e * number); + return numbersList; + } /* TODO: 3. Create a method named isEmpty that accepts one parameter: @@ -64,7 +71,9 @@ public ArrayList getFavouriteNumbers() { The method must return a boolean that indicates whether the provided list is empty or not */ - + public boolean isEmpty(ArrayList strList) { + return strList.isEmpty(); + } /* TODO: 4. Create a method named addIngredient that accepts two parameters in this order: @@ -73,7 +82,10 @@ public ArrayList getFavouriteNumbers() { The method must add the second parameter into the list provided and then return the list */ - + public ArrayList addIngredient(ArrayList stringList, String str) { + stringList.add(str); + return stringList; + } /* TODO: 5. Create a method named removeIngredient that accepts two parameters in this order: @@ -82,7 +94,10 @@ public ArrayList getFavouriteNumbers() { The method must remove the second parameter from the list and then return the list */ - + public ArrayList removeIngredient(ArrayList strList1, String str1) { + strList1.remove(str1); + return strList1; + } /* TODO: 6. Create a method named containsIngredient that accepts two parameters in this order: @@ -91,6 +106,7 @@ public ArrayList getFavouriteNumbers() { The method must return a boolean that indicates whether the second parameter exists in the provided list */ - - + public boolean containsIngredient(ArrayList strList, String str) { + return strList.contains(str); + } }