diff --git a/src/main/java/com/booleanuk/core/Exercise.java b/src/main/java/com/booleanuk/core/Exercise.java index d31a45c..1782c2f 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,6 +45,11 @@ public ArrayList getFavouriteNumbers() { second number contained in the list that is returned from getFavouriteNumbers */ + public int getSecondNumber(){ + List res = getFavouriteNumbers(); + return res.get(1); + } + /* @@ -56,6 +62,11 @@ public ArrayList getFavouriteNumbers() { https://www.programiz.com/java-programming/library/arraylist/replaceall */ + public ArrayList multiply(ArrayList ls, int n){ + ls.replaceAll(k -> k * n); + return ls; + } + /* @@ -65,6 +76,10 @@ public ArrayList getFavouriteNumbers() { */ + public boolean isEmpty(ArrayList ls){ + return ls.isEmpty(); + } + /* TODO: 4. Create a method named addIngredient that accepts two parameters in this order: @@ -73,6 +88,10 @@ public ArrayList getFavouriteNumbers() { The method must add the second parameter into the list provided and then return the list */ + public ArrayList addIngredient(ArrayList ls, String str){ + ls.add(str); + return ls; + } /* @@ -82,6 +101,11 @@ public ArrayList getFavouriteNumbers() { The method must remove the second parameter from the list and then return the list */ + public ArrayList removeIngredient(ArrayList ls, String str){ + ls.remove(str); + return ls; + } + /* @@ -91,6 +115,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 ls, String str){ + return ls.contains(str); + } }