From f2f966df7ef6bd740eb65b61b0f029607ab86459 Mon Sep 17 00:00:00 2001 From: TMajlu Date: Tue, 13 Aug 2024 12:54:27 +0200 Subject: [PATCH] Did the Core exercises. --- .../java/com/booleanuk/core/Exercise.java | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/booleanuk/core/Exercise.java b/src/main/java/com/booleanuk/core/Exercise.java index d31a45c..2a2338c 100644 --- a/src/main/java/com/booleanuk/core/Exercise.java +++ b/src/main/java/com/booleanuk/core/Exercise.java @@ -44,6 +44,10 @@ public ArrayList getFavouriteNumbers() { second number contained in the list that is returned from getFavouriteNumbers */ + public int getSecondNumber(){ + return getFavouriteNumbers().get(1); + } + /* @@ -56,14 +60,22 @@ public ArrayList getFavouriteNumbers() { https://www.programiz.com/java-programming/library/arraylist/replaceall */ + public ArrayList multiply(ArrayList numlist, int num) { + for (int i=0; i strings){ + return strings.isEmpty(); + } /* @@ -73,7 +85,10 @@ public ArrayList getFavouriteNumbers() { The method must add the second parameter into the list provided and then return the list */ - + public ArrayList addIngredient(ArrayList strings, String newString){ + strings.add(newString); + return strings; + } /* TODO: 5. Create a method named removeIngredient that accepts two parameters in this order: @@ -82,7 +97,14 @@ public ArrayList getFavouriteNumbers() { The method must remove the second parameter from the list and then return the list */ - + public ArrayList removeIngredient(ArrayList strings, String newString){ + for (int i=0; i getFavouriteNumbers() { The method must return a boolean that indicates whether the second parameter exists in the provided list */ + public boolean containsIngredient(ArrayList strings, String newString){ + return strings.contains(newString); + } }