diff --git a/src/main/java/com/booleanuk/core/Exercise.java b/src/main/java/com/booleanuk/core/Exercise.java index d31a45c..b59f7fa 100644 --- a/src/main/java/com/booleanuk/core/Exercise.java +++ b/src/main/java/com/booleanuk/core/Exercise.java @@ -44,7 +44,9 @@ public ArrayList getFavouriteNumbers() { second number contained in the list that is returned from getFavouriteNumbers */ - + public int getSecondNumber(){ + return getFavouriteNumbers().get(1); + } /* TODO: 2. Create a method named multiply that accepts two parameters in this order: @@ -56,7 +58,10 @@ public ArrayList getFavouriteNumbers() { https://www.programiz.com/java-programming/library/arraylist/replaceall */ - + public ArrayList multiply(ArrayList listOfNumbers, int factor){ + listOfNumbers.replaceAll(nr -> nr * factor); + return listOfNumbers; + } /* TODO: 3. Create a method named isEmpty that accepts one parameter: @@ -64,7 +69,9 @@ public ArrayList getFavouriteNumbers() { The method must return a boolean that indicates whether the provided list is empty or not */ - + public boolean isEmpty (ArrayList list){ + return list.isEmpty(); + } /* TODO: 4. Create a method named addIngredient that accepts two parameters in this order: @@ -73,7 +80,10 @@ public ArrayList getFavouriteNumbers() { The method must add the second parameter into the list provided and then return the list */ - + public ArrayList addIngredient (ArrayList listOfIngredients, String ingredient){ + listOfIngredients.add(ingredient); + return listOfIngredients; + } /* TODO: 5. Create a method named removeIngredient that accepts two parameters in this order: @@ -82,6 +92,10 @@ public ArrayList getFavouriteNumbers() { The method must remove the second parameter from the list and then return the list */ + public ArrayList removeIngredient (ArrayList listOfIngredients, String ingredient){ + listOfIngredients.remove(ingredient); + return listOfIngredients; + } /* @@ -91,6 +105,8 @@ public ArrayList getFavouriteNumbers() { The method must return a boolean that indicates whether the second parameter exists in the provided list */ - + public boolean containsIngredient (ArrayList listOfIngredients, String ingredient){ + return listOfIngredients.contains(ingredient); + } }