From e324fcb9300c79b0487369c58221bad1a4142b7e Mon Sep 17 00:00:00 2001 From: Lucas Holter Date: Wed, 6 Aug 2025 13:14:26 +0200 Subject: [PATCH] Solution --- .../java/com/booleanuk/core/Exercise.java | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/booleanuk/core/Exercise.java b/src/main/java/com/booleanuk/core/Exercise.java index d31a45c..06210a9 100644 --- a/src/main/java/com/booleanuk/core/Exercise.java +++ b/src/main/java/com/booleanuk/core/Exercise.java @@ -43,7 +43,9 @@ public ArrayList getFavouriteNumbers() { 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 int getSecondNumber(){ + return getFavouriteNumbers().get(1); + } /* @@ -55,7 +57,12 @@ public ArrayList getFavouriteNumbers() { Use the ArrayList's replaceAll method to iterate through the ArrayList and replace each value with its double https://www.programiz.com/java-programming/library/arraylist/replaceall */ - + public ArrayList multiply(ArrayList list, int num){ + for(int i = 0; i < list.size(); i++){ + list.set(i, list.get(i)*num); + } + return list; + } /* @@ -63,7 +70,9 @@ public ArrayList getFavouriteNumbers() { - A list of strings The method must return a boolean that indicates whether the provided list is empty or not */ - + public boolean isEmpty(ArrayList strs){ + return strs.isEmpty(); + } /* @@ -72,7 +81,10 @@ public ArrayList getFavouriteNumbers() { - A string The method must add the second parameter into the list provided and then return the list */ - + public ArrayList addIngredient(ArrayList strs, String str){ + strs.add(str); + return strs; + } /* @@ -81,7 +93,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 strs, String str){ + strs.remove(str); + return strs; + } /* @@ -90,7 +105,9 @@ public ArrayList getFavouriteNumbers() { - A string The method must return a boolean that indicates whether the second parameter exists in the provided list */ - + public boolean containsIngredient(ArrayList strs, String str){ + return strs.contains(str); + } }