Skip to content

Commit

Permalink
Finished Exercise
Browse files Browse the repository at this point in the history
  • Loading branch information
Espen Solhaug committed Jan 11, 2024
1 parent 053080d commit 9c33dce
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/main/java/com/booleanuk/core/Exercise.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ 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() {
return getFavouriteNumbers().get(1);
}


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


public ArrayList<Integer> multiply(ArrayList<Integer> list, int multiplyBy) {
list.replaceAll(e -> (e*multiplyBy));
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> list) {
return list.isEmpty();
}



/*
Expand All @@ -73,7 +82,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> list, String ingredient) {
list.add(ingredient);
return list;
}

/*
TODO: 5. Create a method named removeIngredient that accepts two parameters in this order:
Expand All @@ -82,7 +94,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> list, String ingredient) {
list.remove(ingredient);
return list;
}

/*
TODO: 6. Create a method named containsIngredient that accepts two parameters in this order:
Expand All @@ -91,6 +106,8 @@ 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> list, String ingredient) {
return list.contains(ingredient);
}

}

0 comments on commit 9c33dce

Please sign in to comment.