Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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: GroceryListjava
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 MAXITEMS representing the maximum number of items in
the list ieThe 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
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: etc.. to locate the item in the array
to modify and quantity as an integer 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
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started