Question: GroceryList Class: Name your class as: GroceryList . java Create a Java class named GroceryList to represent a list of items to buy from the

GroceryList Class:
Name your class as: GroceryList.java
Create a Java class named GroceryList to represent a list of items to buy from the market. This
class should have the following attributes and methods:
Fields :
An integer constant named MAX_ITEMS representing the maximum number of items in
the list (i.e.,10).(The constant should be final and static)
Declare an array of GroceryItemOrder named items which holds the objects of
GroceryItemOrder class. The array should be private.
An integer named numItems to store the number of the items currently in the list. It
should be private.
Constructor:
GroceryList Doesnt receive any arguments but the constructor instantiates the items
array with the GroceryItemOrder as the type of the array.
Sets the numItems field to value 0.
Methods (be certain to declare the header of each method as listed here):
add receives the item (as a GroceryItemOrder object : item ) and appends the item to
the list and updates the numItem value.It doesnt return anything.
getNumItems doesnt take any arguments but it returns the total number of items in the
list. The return type is integer.
getTotalCost doesnt take any arguments but it returns the total cost of all the items in
the list. (Hint: use a loop to iterate through the array to calculate the total cost of all
items). The return type is double.
modifyItem receives an index (as an integer: 0,1,2,5 etc..) to locate the item in the array
to modify and quantity (as an integer 1,2,3,4,5 etc..) to replace the existing quantity with
new quantity. It doesnt return anything.
Please make sure to enter the index of the item correctly to modify Item (Index
starts from 0)
toString doesnt receive any arguments but it returns the String of all the current items
in the list. See the sample program for the format of the returning string.
(The driver program or main method is in the GroceryMain.java to operate on these classes)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!