X951: For-Each Loops 6

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

Here's what the FoodItem class looks like:

public class FoodItem
{
    private double price;

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

    public double getPrice()
    {
        return price;
    }
}

The method below should calculate the total price of all FoodItems in the bag. Finish the body of this for-each loop to make that happen!

Your Answer:

Reset

Practice a different Java exercise

Feedback

Your feedback will appear here when you check your answer.