Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

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

Databases And Python Programming MySQL MongoDB OOP And Tkinter

Authors: R. PANNEERSELVAM

1st Edition

9357011331, 978-9357011334

More Books

Students also viewed these Databases questions

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago