Question
For this assignment, create a method that will turn a fixed-size arrayBag into a set. A Set is an abstract data type somewhat similar to
For this assignment, create a method that will turn a fixed-size arrayBag into a set.
A Set is an abstract data type somewhat similar to a Bag, they can store a finite collection of objects without any particular order. However, unlike a Bag, a Set cannot contain duplicates. The add() method for a Set is therefore very similar to the add() method for a Bag, with the additional requirement that it must first confirm that the item being added is unique. Write the member method addLikeASet that implements the following logic:
When invoked the method takes the T parameter anEntry and determines if anEntry already exists in the bag.
If the bag does not already contain anEntrythen the method attempts to add it to the bag, and return true.
If the bag already contained anEntry the method does not attempt to add anEntryand returns false.
Again, this arrayBag is of a fixed size. It will nothave the expandCapacity method available. Once the bag is full, nothing else can be added. Remember to review the Bags module, specifically the add() method implementation for Bags as it will be helpful here.
Your implementation code for this problem may NOT access/invoke any of the Bag API methods but, since it is a member method, your code may access the fields numberOfEntries (an int) and contents (an array of items in the bag). Your solution code may also include helper methods.
Can you help me with it by telling what did I miss in my code?( since Im not getting full marks)
Your Answer: Feedback 0.8/ Result Behavior Test adding one item then attempting to add its duplicate. Test addLikeASet 0 by attempting add of a number of items, the last item attempted being a duplicate of the first item successfully added. Test addLikeASet0 by attempting add of a number of items, the last item attempted being a duplicate of the last item successfully added. hidden test(s)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started