Question
A set is a collection of items without repetitions. The goal of this assign- ment is to implement a set as a data structure. Do
A set is a collection of items without repetitions. The goal of this assign- ment is to implement a set as a data structure. Do the following.
1. Starting with the template attached, implement a generic class SetT that maintains a set of items of generic type T using the class ArrayListT in the Java API. Your Set class must provide the following instance methods:
add: that adds a new item. (Ignore if already in the set.) remove: that removes an item. (Ignore if not in the set.)
membership: that returns true if a given item is in the set and false otherwise.
toString: that returns a string with the list of the items in the set.
2. Write a testSet class with a main() method that tests all the operations of the Set class above. That is, create an empty set A of integers, obtain from the user some integers and store some in A, display the set using toString(), obtain from the user some integers and remove them from A using remove(), display the set using toString(), obtain an integer from the user and check whether it is in A or not using membership() and display the result.
3*******. Expand your class SetT with the following static methods, and expand your testSet class to test them.
union: that returns the union of two given sets. intersection: that returns the intersection of two given sets.
difference: that returns the difference between two given sets.
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