Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a class named GroceryList that represents a list of items to buy from the market, and another class named GroceryItemOrder that represents a request

image text in transcribed

Write a class named GroceryList that represents a list of items to buy from the market, and another class named GroceryItemOrder that represents a request to purchase a particular item in a given quantity (e.g., four boxes of cookies). The GroceryList class should use an array field to store the grocery items and to keep track of its size (number of items in the list so far). Assume that a grocery list will have no more than 10 items. A GroceryList object should have the following methods: public GroceryList () Constructs a new empty grocery list. public void add (GroceryItemOrder item) Adds the given item order to this list if the list has fewer than 10 items. public double getTotalCost() Returns the total sum cost of all grocery item orders in this list. The GroceryItemOrder class should store an item quantity and a price per unit. A GroceryItemOrder object should have the following methods: public GroceryltemOrder (String name, int quantity, double pricePerUnit) Constructs an item order to purchase the item with the given name, in the given quantity, which costs the given price per unit. public double getCost() Returns the total cost of this item in its given quantity. For example, four boxes of cookies that cost 2.30 per unit have a total cost of 9.20. public void setQuantity (int quantity) Sets this grocery item's quantity to be the given value

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Antipatterns Avoiding The Pitfalls Of Database Programming

Authors: Bill Karwin

1st Edition

1680508989, 978-1680508987

More Books

Students also viewed these Databases questions