0
/ 1.0
For this question you will be using FoodItem
objects and one GroceryBag
object.
public class FoodItem { private int price; private...
For this question you will be using FoodItem
objects and one GroceryBag
object.
public class FoodItem
{
private int price;
private boolean onSale;
public FoodItem(int p, boolean s)
{
this.price = p;
this.onSale = s;
}
public int getPrice()
{
return price;
}
public boolean isOnSale()
{
return onSale;
}
public void setOnSale(boolean onSale) {
this.onSale = onSale;
}
}
Remember that you can use getFoodList()
to access the contents of the GroceryBag
for use in a for-each loop.
Complete the method below so that it uses a for-each loop to repeat over all food items
in the grocery bag, setting the "on sale" attribute of each food item to the opposite
of its current value (turning each "on sale" item to not on sale, and vice versa).
Your feedback will appear here when you check your answer.