From 5e1925f762675585e36a42119e94d45686c2f691 Mon Sep 17 00:00:00 2001 From: Richard Persson Date: Wed, 6 Aug 2025 15:23:16 +0200 Subject: [PATCH] Completed Excercise --- .../java/com/booleanuk/core/Exercise.java | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/booleanuk/core/Exercise.java b/src/main/java/com/booleanuk/core/Exercise.java index d31a45c..3d7662b 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.function.Consumer; public class Exercise extends ExerciseBase { /* @@ -44,6 +45,9 @@ public ArrayList getFavouriteNumbers() { second number contained in the list that is returned from getFavouriteNumbers */ + public int getSecondNumber(){ + return getFavouriteNumbers().get(1); + } /* @@ -56,6 +60,12 @@ public ArrayList getFavouriteNumbers() { https://www.programiz.com/java-programming/library/arraylist/replaceall */ + public ArrayList multiply(ArrayList list, int multiplier) { + + list.replaceAll(x -> x*multiplier); + return list; + } + /* @@ -64,8 +74,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: - A list of strings @@ -73,6 +84,10 @@ public ArrayList getFavouriteNumbers() { The method must add the second parameter into the list provided and then return the list */ + public ArrayList addIngredient(ArrayList list, String ingredient) { + list.add(ingredient); + return list; + } /* @@ -82,7 +97,10 @@ public ArrayList getFavouriteNumbers() { The method must remove the second parameter from the list and then return the list */ - + public ArrayList removeIngredient(ArrayList list, String ingredient) { + list.remove(ingredient); + return list; + } /* TODO: 6. Create a method named containsIngredient that accepts two parameters in this order: @@ -91,6 +109,9 @@ public ArrayList getFavouriteNumbers() { The method must return a boolean that indicates whether the second parameter exists in the provided list */ + public boolean containsIngredient(ArrayList list, String ingredient) { + return list.contains(ingredient); + } }