Question: code in java please 3. Implement an ADT Bag using Linked Data. For that, create a class named MyLinkedBag that should also implements the same

code in java please

code in java please 3. Implement an ADT Bag using Linked Data.

For that, create a class named MyLinkedBag that should also implements the

3. Implement an ADT Bag using Linked Data. For that, create a class named MyLinkedBag that should also implements the same BagInterface that was implemented by your MyArrayBag class in Assignment-1. As a result, your MyLinkedBag class will have to implement all methods defined in the interface. [ 30 points] This class should: (a) Have a private instance variable called 'numNodes', whose initial value should be 0 . This variable will store an integer value, which will represent the count of node elements in the bag at any point in time (b) Have a default instance variable called 'firstNode' that will store a node object, which will be implemented through an inner class called 'Node', as outlined below. This variable will represent the starting node that can then be used to traverse through all other nodes in the bag (c) Have a no-arg constructor (d) Have the following methods: i. add(a gym object as argument) - This method should add a GymEquipment object and return true to indicate if add was successful and false otherwise - This method should take a gym object as an argument - This method will create a new Node object and set its data attribute to the gym object object and set the next attribute of the new node to be what was previously firstNode and the firstNode attribute to this newly created node Note: Feb 18, 2023 The add method should handle both conditions, of adding a node to an empty bag, and also the case if the bag had node(s) prior to this addition ii. contains( a gym object as an argument) - This method should check to see if gym object exists in the bag - The method should return true if gym object exists and false otherwise Note: - Keep in mind since a GymEquipment object is stored as data within the linked node, you will need to traverse through the nodes and compare each node's gym object to object coming in as argument to find the match - You will need a way to compare two gym objects to check equality iii. remove() - This method should delete the first node of the bag - This method should return true if successful and false otherwise Note: Once the deletion is completed, the firstNode attribute should point to what was previously the node next to first node iv. remove(gym object as an argument) - This method deletes gym object in the bag - This method should return true if successful and false otherwise Note: - As in the case of contains method above, you will need to traverse through the nodes and compare each node's data to gym object to find the match - As in the case of contains method above, you will need a way to compare two gym objects objects to check equality v. toArray() - The method should return an array all gym objects in the bag - Keep in mind that since gym objects are stored as data within the linked nodes of the bag, you will need to traverse through the nodes within the bag and build the array of gym objects as retrieved from each node Since you are creating MyLinkedBag class, you will not be using an array to store objects. Instead, you will be creating a Node class, as inner class within your MyLinkedBag class, to facilitate storing and retrieving stored objects [ 20 points] This Node inner class should: (a) Have an instance variable called 'data', that will store objects of type GymEquipment p4 Feb 18, 2023 (b) Have an instance variable called 'next', that will store a Node object, which represents the node next to current node (c) Have a no-arg constructor (d) Have a 1-arg constructor, that takes an object as an argument (e) Have a 2-arg constructor, that takes an object and Node object as two arguments. This constructor should set the object to the data attribute and Node object to the next node attribute of the current node, as discussed in class (f) Have getters and setters for each of the 2 instance variables for the class

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!