Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions src/main/java/com/booleanuk/core/Exercise.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.booleanuk.core;

import com.booleanuk.helpers.ExerciseBase;

import java.util.ArrayList;

import com.booleanuk.helpers.ExerciseBase;

public class Exercise extends ExerciseBase {
/*
A List is like an array but provides a much easier interface to the items it stores, for example:
Expand Down Expand Up @@ -44,7 +44,9 @@ public ArrayList<Integer> getFavouriteNumbers() {
second number contained in the list that is returned from getFavouriteNumbers
*/


public int getSecondNumber() {
return getFavouriteNumbers().get(1);
}

/*
TODO: 2. Create a method named multiply that accepts two parameters in this order:
Expand All @@ -56,15 +58,20 @@ public ArrayList<Integer> getFavouriteNumbers() {
https://www.programiz.com/java-programming/library/arraylist/replaceall
*/


public ArrayList<Integer> multiply(ArrayList<Integer> numbers, int number) {
numbers.replaceAll(i -> i * number);
return numbers;
}

/*
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<String> list) {
return list.isEmpty();
}

/*
TODO: 4. Create a method named addIngredient that accepts two parameters in this order:
Expand All @@ -73,7 +80,10 @@ public ArrayList<Integer> getFavouriteNumbers() {
The method must add the second parameter into the list provided and then return the list
*/


public ArrayList<String> addIngredient(ArrayList<String> ingredients, String newIngredient) {
ingredients.add(newIngredient);
return ingredients;
}

/*
TODO: 5. Create a method named removeIngredient that accepts two parameters in this order:
Expand All @@ -82,7 +92,10 @@ public ArrayList<Integer> getFavouriteNumbers() {
The method must remove the second parameter from the list and then return the list
*/


public ArrayList<String> removeIngredient(ArrayList<String> ingredients, String newIngredient) {
ingredients.remove(newIngredient);
return ingredients;
}

/*
TODO: 6. Create a method named containsIngredient that accepts two parameters in this order:
Expand All @@ -91,6 +104,9 @@ public ArrayList<Integer> getFavouriteNumbers() {
The method must return a boolean that indicates whether the second parameter exists in the provided list
*/

public boolean containsIngredient(ArrayList<String> ingredients, String ingredient) {
return ingredients.contains(ingredient);
}


}
Loading