Class GroceryList
Object
GroceryList
Used to hold and modify our list of Grocery objects.
This GroceryList class has a single instance variable, an ArrayList.
The previous Grocery objects can be added and removed from the ArrayList usign the many methods.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddGrocery(Grocery groc) Adds the given Grocery parameter to the grocList.getAisleGroceries(int aisle) Loops through the grocList and checks each Grocery object's aisle against the aisle parameter provided.Gets the summation of all prices and calories contained in the GroceryList's Grocery objects.voidremoveGrocery(String grocName) Loops through the grocList until the given grocName is found then it is removed from the list.toString()Loops through the grocList ArrayList and appends the toString() of each Grocery object to the strList variable.
-
Field Details
-
grocList
-
-
Constructor Details
-
GroceryList
public GroceryList()
-
-
Method Details
-
getGrocList
-
addGrocery
Adds the given Grocery parameter to the grocList.- Parameters:
groc- Grocery object to be added to the ArrayList
-
removeGrocery
Loops through the grocList until the given grocName is found then it is removed from the list.Grocery.getName()will prove useful.- Parameters:
grocName- Name of Grocery object to remove.
-
toString
Loops through the grocList ArrayList and appends the toString() of each Grocery object to the strList variable. Using theGrocery.toString()method from the Grocery class will be handy for this method.Each entry will have newline character between them. '\n'
Broccoli which costs: $2.99, located in the aisle 12. Cheese which costs: $1.50, located in the aisle 3. Rop Tamen which costs: $4.25, located in the aisle 14.
-
getAisleGroceries
Loops through the grocList and checks each Grocery object's aisle against the aisle parameter provided. Each Grocery that has the same aisle has itsGrocery.toString()added to the aisleString variable, along with a newline character, '\n'.Grocery.getAisle()will come in handy.- Parameters:
aisle- Int indicating which aisle groceries are being looked for.
-
getTotals
Gets the summation of all prices and calories contained in the GroceryList's Grocery objects.
-