Answered step by step
Verified Expert Solution
Link Copied!

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: 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

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

Database And Expert Systems Applications 22nd International Conference Dexa 2011 Toulouse France August/September 2011 Proceedings Part 1 Lncs 6860

Authors: Abdelkader Hameurlain ,Stephen W. Liddle ,Klaus-Dieter Schewe ,Xiaofang Zhou

2011th Edition

3642230873, 978-3642230875

More Books

Students also viewed these Databases questions

Question

How does corruption limit investment and economic growth?

Answered: 1 week ago

Question

Describe the appropriate use of supplementary parts of a letter.

Answered: 1 week ago