Created
August 23, 2017 17:21
-
-
Save un4ckn0wl3z/8e72675d77f1cc5599d19fd2cc4c7472 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.un4; | |
import java.util.ArrayList; | |
/** | |
* Created by UN4CKN0WL3Z on 23/08/2017. | |
*/ | |
public class GroceryList { | |
private ArrayList<String> groceryList = new ArrayList<>(); | |
public void addGroceryItem(String item){ | |
groceryList.add(item); | |
} | |
public void printGroceryList(){ | |
System.out.println("You have " + groceryList.size() + | |
" items in your grocery list"); | |
for (int i=0;i<groceryList.size();i++){ | |
System.out.println((i+1) + ". " + groceryList.get(i)); | |
} | |
} | |
public void modifyGroceryItem(int position,String newItem){ | |
groceryList.set(position,newItem); | |
System.out.println("Grocery item " + (position+1) + " has been modified."); | |
} | |
public void removeGroceryItem(int position){ | |
String theItem = groceryList.get(position); | |
groceryList.remove(position); | |
System.out.println("Grocery item " + theItem + " in position "+(position+1) + " has been deleted."); | |
} | |
public String findItem(String searchItem){ | |
// boolean exists = groceryList.contains(searchItem); | |
int position = groceryList.indexOf(searchItem); | |
if(position>= 0){ | |
return groceryList.get(position); | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment