From efdbda51a5ae62b01331b4b369c800206b608a0f Mon Sep 17 00:00:00 2001 From: Marie Helene Hansen Date: Wed, 6 Aug 2025 12:44:22 +0200 Subject: [PATCH] task complete --- .../java/com/booleanuk/core/Exercise.java | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/booleanuk/core/Exercise.java b/src/main/java/com/booleanuk/core/Exercise.java index d31a45c..7f4c731 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 { /* @@ -39,12 +40,19 @@ public ArrayList getFavouriteNumbers() { return list; } + public int getSecondNumber() { + return getFavouriteNumbers().get(1); + } + /* 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 ArrayList multiply(ArrayList inputList, int inputNum) { + inputList.replaceAll(e -> e*inputNum); + return inputList; + } /* TODO: 2. Create a method named multiply that accepts two parameters in this order: @@ -56,7 +64,9 @@ public ArrayList getFavouriteNumbers() { https://www.programiz.com/java-programming/library/arraylist/replaceall */ - + public boolean isEmpty(ArrayList inputList) { + return inputList.isEmpty(); + } /* TODO: 3. Create a method named isEmpty that accepts one parameter: @@ -64,7 +74,10 @@ public ArrayList getFavouriteNumbers() { The method must return a boolean that indicates whether the provided list is empty or not */ - + public ArrayList addIngredient(ArrayList inputList, String ingredient) { + inputList.add(ingredient); + return inputList; + } /* TODO: 4. Create a method named addIngredient that accepts two parameters in this order: @@ -74,7 +87,10 @@ public ArrayList getFavouriteNumbers() { */ - + public ArrayList removeIngredient(ArrayList strings, String string) { + strings.remove(1); + return strings; + } /* TODO: 5. Create a method named removeIngredient that accepts two parameters in this order: - A list of strings @@ -83,7 +99,12 @@ public ArrayList getFavouriteNumbers() { */ - + public boolean containsIngredient(ArrayList strings, String string) { + for (String s : strings) { + if (s.equals(string)) return true; + } + return false; + } /* TODO: 6. Create a method named containsIngredient that accepts two parameters in this order: - A list of strings