Question: Implement a class Bag that stores items represented as strings. Items can be repeated. Supply methods for adding an item, and for counting how many

Implement a class Bag that stores items represented as strings. Items can be repeated.

Supply methods for adding an item, and for counting how many times an item has been added:

public void add (String itemName) public int count (String itemName)

Your Bag class should store the data in an ArrayList, where Item is an inner class with two instance variables: the name of the item and the quantity.

public void add (String itemName) public int count (String itemName)

Step by Step Solution

3.46 Rating (149 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To implement the Bag class as described you would create a Java class with an inner Item class that stores item names and quantities The outer Bag cla... View full answer

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 Java Programming Questions!