From 3e40bb34387771a21d74eee92796d4f4f5e974b1 Mon Sep 17 00:00:00 2001 From: Roderick Leito Date: Wed, 6 Aug 2025 12:51:24 +0200 Subject: [PATCH] Finished all exercises --- .../java/com/booleanuk/core/Exercise.java | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/booleanuk/core/Exercise.java b/src/main/java/com/booleanuk/core/Exercise.java index d31a45c..eab5157 100644 --- a/src/main/java/com/booleanuk/core/Exercise.java +++ b/src/main/java/com/booleanuk/core/Exercise.java @@ -43,8 +43,11 @@ 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(); + int num = list.get(1); + return num; + } /* TODO: 2. Create a method named multiply that accepts two parameters in this order: @@ -56,14 +59,23 @@ public ArrayList getFavouriteNumbers() { https://www.programiz.com/java-programming/library/arraylist/replaceall */ + @Override + public ArrayList multiply(ArrayList list, int mltplr) { + for(int i = 0; i list){ + return list.isEmpty(); + } /* @@ -72,7 +84,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 str){ + list.add(str); + return list; + } /* @@ -81,7 +96,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 str){ + list.remove(str); + return list; + } /* @@ -90,7 +108,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 list, String str){ + return list.contains(str); + } }