In: Computer Science
Class GroceryBag
collects instances of class Item in an appropriate
data structure.
Class Item
---------------------------
-String description
-int cost //price in cents
----------------------------
+ [constructor, getters, and a toString() method]
• (Assume
class Item has already been coded)
Class GroceryBag (Highlights)
----------------------------------
-bag // an ArrayList of
<Item>
----------------------------------
assume public methods: constructor, totalBag(), findItem(String
it), listAll(), etc.
• The
ONLY thing you need to do in the space below is to
write java code for the complete method specified:
• In
the space below, write code for a complete method
void showCheapItems()
that will use the ArrayList
bag and which will display all
Items in the bag whose price is below the overall average
of
all the prices of all the items in the bag.
[Hint: average will be the sum divided by the number of
items].
Required: use at least one for-each loop as part of your
method.
please help quickly!!!!!
Below is the snapshot of the program, the user needs to write the program on the java compiler, then he can exutre the program:
Output snapshot of the program: