From 900fc93b849133246e929c7e9c8f649a448ea660 Mon Sep 17 00:00:00 2001 From: Emanuels Zaurins Date: Wed, 6 Aug 2025 12:49:52 +0200 Subject: [PATCH] ex completed --- .../java/com/booleanuk/core/Exercise.java | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/booleanuk/core/Exercise.java b/src/main/java/com/booleanuk/core/Exercise.java index d31a45c..f277429 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,10 @@ public ArrayList getFavouriteNumbers() { second number contained in the list that is returned from getFavouriteNumbers */ + public int getSecondNumber() { + return getFavouriteNumbers().get(1); + } + /* @@ -56,14 +61,21 @@ public ArrayList getFavouriteNumbers() { https://www.programiz.com/java-programming/library/arraylist/replaceall */ + public ArrayList multiply(ArrayList list, int num) { + + list.replaceAll(e -> e * num);; + return list; + } /* TODO: 3. Create a method named isEmpty that accepts one parameter: - A list of strings The method must return a boolean that indicates whether the provided list is empty or not */ - + public boolean isEmpty(ArrayList list){ + return list.isEmpty(); + } /* @@ -73,6 +85,12 @@ 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 s1 ){ + list.add(s1); + return list; + + } + /* @@ -81,7 +99,10 @@ public ArrayList getFavouriteNumbers() { - A string The method must remove the second parameter from the list and then return the list */ - + public ArrayList removeIngredient(ArrayList list, String s1){ + list.remove(s1); + return list; + } /* @@ -91,6 +112,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 s1){ + return list.contains(s1); + } }