Skip to content

Melvin Uthayaseelan. Finished Task 1 #114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
50 changes: 50 additions & 0 deletions src/main/java/com/booleanuk/core/Exercise.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.util.ArrayList;

import java.util.List;
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,6 +45,18 @@ public ArrayList<Integer> getFavouriteNumbers() {
second number contained in the list that is returned from getFavouriteNumbers
*/

public int getSecondNumber(){
ArrayList<Integer> favouriteNumbers = getFavouriteNumbers();

if (favouriteNumbers.size()<2) {
throw new IllegalArgumentException("The Arraylist contains less than two numbers. Please add more!");
}

return favouriteNumbers.get(1);


}



/*
Expand All @@ -57,13 +70,26 @@ public ArrayList<Integer> getFavouriteNumbers() {
*/


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

}





/*
Expand All @@ -75,13 +101,31 @@ public ArrayList<Integer> getFavouriteNumbers() {



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:
- A list of strings
- A string
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;
}



/*
Expand All @@ -92,5 +136,11 @@ public ArrayList<Integer> getFavouriteNumbers() {
*/


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

}



}