Question: Please help with Generic Class and Test set class. 1. Implement a generic class Set(T) that maintains a set of items of generic type T

Please help with Generic Class and Test set class.

1. Implement a generic class Set(T) that maintains a set of items of generic type T using the class LinkedList(T) 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.

(REMINDER: do not violate encapsulation, you can only use List methods.)

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. (REMINDER: you can only store objects.)

3. Based on the big-O running time of each method, argue whether implementing with ArrayList would have been better or not. (A complete answer must include the big-O running time of all methods for each of the implementations. If you do not base your answer on the big-O running time, you get no points.)

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!