X964: For-Each Loops 10

For this question you will be using FoodItem objects and one GroceryBag object.

public class FoodItem
{
    private double price;
    private boolean onSale;

    public FoodItem(double p)
    {
        this.price = p;
    }

    public double getPrice()
    {
        return price;
    }

    public void setPrice(double price)
    {
        this.price = price;
    }

    public boolean isOnSale()
    {
        return onSale;
    }
}

The store today is having a super sale where every item that is on sale is just $1.00! The method below should use a for-each loop to set the price of every item that is on sale to 1.00.

Your Answer:

Reset

Practice a different Java exercise

Feedback

Your feedback will appear here when you check your answer.