Question: Java and please dont use import for anything except for scanner - and please use single or double linked list thank you Q1. Suppose you

Java and please dont use import for anything except for scanner - and please use single or double linked list thank you
Java and please dont use import for anything except for scanner -
and please use single or double linked list thank you Q1. Suppose
you want to design a class to store the contents of grocery
bag that can contain duplicate and unordered items. The size of the

Q1. Suppose you want to design a class to store the contents of grocery bag that can contain duplicate and unordered items. The size of the bag can increase and shrink as necessary and you need to store it to know the current number of items in the bag. Below is the description of the operations that you need to include inside the grocery bag class. O public int getSize() o Task: Gets the size of the bag. o Return the integer number of items currently in the bag public boolean isEmpty o Task: Sees whether the bag is empty Return true if the bag is empty, or false if not. public boolean add(String newitem) Task: Adds a new item to the bag. Increases the number of items by one. o Param: newltem the object to be added as a new item Return true if the addition is successful, or false if not public String remove(String anltem) o Task: Removes the first occurrence of an item. Decreases the number of items by one. o Param anltem: the object to be removed o Return either the entry removed if the removal was successful, or null public void clear o Task: Removes all entries from the bag. Reset the number of items. public void display Task: Displays all items that are in the bag, one per line, in the order in which they occur in the bag. public boolean contains(String anItem); o Task: Tests whether the bag contains a given item. Param anltem: the object that is the desired entry Return true if the bag contains anltem, or false if not O O O public int count(String anltem) o Task: Determines the number of times anltem appears in a bag Param anltem: the object that is the desired item Return: the number of number of times anltem appears in the bag public GroceryBag union(GroceryBag another Bag): o Task: Creates a new bag that combines the contents of the bag and another Bag o Param anotherBag: the Bag that is to be added o Return a combined Bag public GroceryBag intersection(GroceryBag another Bag) Task: Creates a new bag that contains those items that occur in both the bag and another Bag without duplication o Param anotherBag: the Bag that is to be compared Return an intersection Bag Your task is to: 1. Choose the best data structure to represent the grocery bag and the items that it contains (Array, Singly Linked List, Doubly Linked List]. Justify your selection. 2. Implement the class GroceryBag and ltem class using your chosen data structure in Java. 3. Implement the above methods in Java. 4. Provide a test class program. In main, create two GrocerryBag objects, bagi, bag2. Provide a list of actions for the user to choose from according to the shown sample output Make sure to test all the cases. If one case did not work as described, note that in your sample output. Sample output: Welcome to the Local Food Grocery Store: Please choose one of the following: 1) Add item to a bag 2) Remove an item from a bag 3) Clear the contents of a bag 4) Find an item in a bag 5) Find the quantity of an item in a bug 6) Find the total number of items in a big 7) Display the contents of a bag 8) Create the union bag 9) Create the intersection bag 10) Exit 1 Which bag you want to add to, 1 or 2? Enter the items ($ to stop) milk egg carrot apple carrot cheese carrot $ Please choose one of the following: 1) Add item to a bag 2) Remove an item from a bag 3) Clear the contents of a bag 4) Find an item in a bag 5) Find the quantity of an item in a bag 6) Find the total number of items in a bag 7) Display the contents of a bag 8) Create the union bag 9) Create the intersection bag 10) Exit Which bag you want to add to, 1 or 2? 2 Enter the items you want to add, s to stop pasta orange milk eg lettuce Please choose one of the following: 1) Add item to a bag 2) Remove an item from a bag 3) Clear the contents of a bag 4) Find an item in a bag 5) Find the quantity of an item in a bag 6) Find the total number of items in a bag 7) Display the contents of a bag 8) Create the union bag 9) Create the intersection bag 10) Exit 4 Which bag you want to search, 1 or 2? 2 Enter the item you want to find: lettuce lettuce was found in bag2 Please choose one of the following: 1) Add item to a bag 2) Remove an item from a bag 3) Clear the contents of a bag 4) Find an item in a bag 5) Find the quantity of an item in a bag 6) Find the total number of items in a bag 7) Display the contents of a bag 8) Create the union bag 9) Create the intersection bag 10) Exit 8 The union bag of bag1 and bag2 has been created The contents are: milk ess apple carrot cheese carrot pasta orange milk ess lettuce

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!