From 30973365b6e12d475813ff45a4b1d8e22985e74d Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 6 Aug 2025 13:17:23 +0200 Subject: [PATCH] exercise finished --- .../java/com/booleanuk/core/Exercise.java | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/booleanuk/core/Exercise.java b/src/main/java/com/booleanuk/core/Exercise.java index d31a45c..aaf139e 100644 --- a/src/main/java/com/booleanuk/core/Exercise.java +++ b/src/main/java/com/booleanuk/core/Exercise.java @@ -43,6 +43,10 @@ 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(){ + ArrayList list = getFavouriteNumbers(); + return list.get(1); + } @@ -55,42 +59,45 @@ 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 multiplier) { + list.replaceAll(n -> n * multiplier); + 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(); + } + /* TODO: 4. Create a method named addIngredient that accepts two parameters in this order: - - A list of strings + - A list of strings4 - A string 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; + } /* TODO: 5. Create a method named removeIngredient that accepts two parameters in this order: - A list of strings - A string 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: - A list of strings - A string 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); + } }