From 9e88ea78c0e9f4fe9ac309685c8a08d01b3f0b10 Mon Sep 17 00:00:00 2001 From: Connor Stokes Date: Tue, 13 Aug 2024 14:48:48 +0100 Subject: [PATCH] Passes all tests --- .../java/com/booleanuk/core/Exercise.java | 28 +++++++++++++++---- 1 file changed, 23 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..12eadd4 100644 --- a/src/main/java/com/booleanuk/core/Exercise.java +++ b/src/main/java/com/booleanuk/core/Exercise.java @@ -43,7 +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); + } /* @@ -56,6 +59,11 @@ public ArrayList getFavouriteNumbers() { https://www.programiz.com/java-programming/library/arraylist/replaceall */ + public ArrayList multiply(ArrayList numbers, int multiplier) { + numbers.replaceAll(e -> e * multiplier); + return numbers; + } + /* @@ -63,7 +71,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 list) { + return list.isEmpty(); + } /* @@ -72,7 +82,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 list, String ingredient) { + list.add(ingredient); + return list; + } /* @@ -81,7 +94,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 ingredient) { + list.remove(ingredient); + return list; + } /* @@ -91,6 +107,8 @@ 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); + } }