Skip to content
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

Noah Lennestad #90

Open
wants to merge 1 commit 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
42 changes: 40 additions & 2 deletions src/main/java/com/booleanuk/core/Exercise.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +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);
}

/*
TODO: 2. Create a method named multiply that accepts two parameters in this order:
Expand All @@ -55,6 +56,14 @@ public ArrayList<Integer> getFavouriteNumbers() {
Use the ArrayList's replaceAll method to iterate through the ArrayList and replace each value with its double
https://www.programiz.com/java-programming/library/arraylist/replaceall
*/
public ArrayList<Integer> multiply(ArrayList<Integer> list, int number) {
for(int i = 0; i < list.size(); i++) {
int newNumber = list.get(i) * number;
list.set(i, newNumber);
}
return list;
}




Expand All @@ -63,6 +72,9 @@ public ArrayList<Integer> getFavouriteNumbers() {
- 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 @@ -72,7 +84,11 @@ public ArrayList<Integer> getFavouriteNumbers() {
- A string
The method must add the second parameter into the list provided and then return the list
*/
public ArrayList<String> addIngredient(ArrayList<String> list, String text){
list.add(text);

return list;
}


/*
Expand All @@ -81,6 +97,16 @@ public ArrayList<Integer> getFavouriteNumbers() {
- A string
The method must remove the second parameter from the list and then return the list
*/
public ArrayList<String> removeIngredient(ArrayList<String> list, String text){
for(int i = 0; i < list.size(); i++){
if(list.get(i).equals(text)){
list.remove(i);

}

}
return list;
}
Copy link

@adam-searle adam-searle Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be simplified, eg:

public ArrayList<String> removeIngredient(ArrayList<String> list, String text) {
    list.remove(text);
    return list;
}




Expand All @@ -90,6 +116,18 @@ 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> list, String text){
for(int i = 0; i < list.size(); i++){
if(list.get(i).equals(text)){
return true;

}

}
return false;


}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again could be simplified by making use of pre-existing methods. eg:

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




Expand Down
Loading