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
27 changes: 26 additions & 1 deletion src/main/java/com/booleanuk/core/Exercise.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.booleanuk.helpers.ExerciseBase;

import java.util.ArrayList;
import java.util.List;

public class Exercise extends ExerciseBase {
/*
Expand Down Expand Up @@ -43,6 +44,13 @@ public ArrayList<Integer> 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 () {
List<Integer> list = getFavouriteNumbers();

int favouriteNumber = list.get(1);
return favouriteNumber;

}



Expand All @@ -56,14 +64,21 @@ public ArrayList<Integer> getFavouriteNumbers() {
https://www.programiz.com/java-programming/library/arraylist/replaceall
*/

public ArrayList<Integer> multiply (ArrayList<Integer> list, int wholeNum) {

list.replaceAll(number -> number * wholeNum);
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<String> strings) {
return strings.isEmpty();
}


/*
Expand All @@ -73,6 +88,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 string) {
ingredients.add(string);
return ingredients;
}


/*
Expand All @@ -82,6 +101,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 string) {
ingredients.remove(string);
return ingredients;
}


/*
Expand All @@ -90,7 +113,9 @@ public ArrayList<Integer> getFavouriteNumbers() {
- A string
The method must return a boolean that indicates whether the second parameter exists in the provided list
*/

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


}
Loading