question archive The assignment Instructions I'm supposed to write a class named GroceryList that represents a person's 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 (example: 4 boxes of cookies)

The assignment Instructions I'm supposed to write a class named GroceryList that represents a person's 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 (example: 4 boxes of cookies)

Subject:Computer SciencePrice: Bought3

The assignment Instructions
I'm supposed to write a class named GroceryList that represents a person's 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 (example: 4 boxes of cookies).
The GroceryList class should use an array field to store the grocery items, as well as keeping 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 is not full (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 price per unit. A GroceryItemOrder object should have the following methods:

public GroceryItemOrder(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, 4 boxes of cookies that are 2.30 per unit have a cost of 9.20.
public void setQuantity(int quantity) - Sets this grocery item's quantity to be the given value.

I'm pretty sure I have the GroceryItemOrder class done correctly, and I have my test/main method class done... It's the GroceryList that I seem to have trouble working with the array and using it in conjunction with the other class. Here's what I have:                                                                                                                                                                                                               I also need to create a client class that will instantiate an object of the GroceryList. I cannot find out what is wrong with my code. If possible please peer review my work and provide me with ways to correct my work.

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE