Question: import java.util.ArrayList; public class GroceryList { ArrayList grocList = new ArrayList (); public ArrayList getGrocList() { return grocList; } public void addGrocery(Grocery groc) { grocList.add(groc);

import java.util.ArrayList; public class GroceryList { ArrayList grocList = new ArrayList(); public ArrayList getGrocList() { return grocList; } public void addGrocery(Grocery groc) { grocList.add(groc); } /* * Student Self-Explanation: * * * */ public void removeGrocery(String grocName) { for(Grocery g: grocList) { if(false) { //TODO Student grocList.remove(g); break; } } } public String toString() { String strList = ""; //TODO Student return strList; } public String getAisleGroceries(int aisle) { String aisleString = ""; //TODO Student return aisleString; } public String getTotals() { double priceSum = 0; int caloriesSum = 0; for(Grocery g: grocList) { priceSum += g.getPrice(); caloriesSum += g.getCalories(); } String rtn = "The total price of this Grocery Trip: $" + priceSum + ' '; rtn += "The total calories of this Grocery Trip: " + caloriesSum + "cal "; return rtn; } }

import java.util.ArrayList; public class GroceryList { ArrayList grocList = new ArrayList(); publicArrayList getGrocList() { return grocList; } public void addGrocery(Grocery groc) { grocList.add(groc);

public void removegrocery(String [grocName) Loops through the grocList until the : tn it is removed from the list. Grocery. getName () will prove uscful. Parameters: grocName - Name of Grocery object to remove. tostring public Stringer toString() Loops through the grocList ArrayList and appends the toString() of each Grocery object to the strList variable. Using the Grocery. toSt ring () method from the Grocery class will be handy for this method. Fach 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 ais 14 . Overrides: toString B in class 0bject A public String getAisleGroceries(int aisle) newline character, ' . Grocery.getAis le ( ) will come in handy. Parameters: ais le - Int indicating which aisle groceries are being looked for. getTotals public String getTotals() Gets the summation of all prices and calories contained in the GroceryList's Grocery objects

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!