Starting from:

$30

Assignment 4 Solution

Assignment 4 Skills




Designing an ADT




Creating an interface based on ADT




Implementing an ADT using an interface




Assignment 4 Background




For this assignment, we wish to implement a Set Data Structure. We will de ne our Set Abstract Data Type (ADT) as: a Set is an unordered, nite collection of objects with no duplicates.




Our Set ADT is similar to our Bag ADT, with one notable di erence: duplicates were allowed in bags, but are not allowed in sets.




Assignment 4 Requirements




(25%) Write an interface called SetInterface. This interface will de ne required set operations. This interface should have the following methods de ned:



Add, that adds an element to the set if able.



Remove (random), that removes a (random) element from the set. This does not have to be truly random.



Remove (speci ed), that removes a speci ed element from the set if able.



isEmpty, that determines the emptyness of the set.



getCurrentSize, that returns the number of elements currently in the set.



clear, that removes all elements from the set.



contains, that determines whether a speci ed element is in the set.



union, that returns a set with all of the elements of this set, and the speci ed set.



intersection, that returns a set with all of the common elements in this set, and the speci ed set.



di erence, that returns a set with all of the elements in this set, that are not in the speci ed set.



(10%) Provide comments for the interface as necessary being sure to document:



the expected behavior of each method.



the return types, and expected return values (if any).



the conditions for success/failure, and expected handling of such (if any).



anything else of importance in your design choices.



(40%) Write a class called ArraySet that implements the SetInterface interface. This class should include the following:



an array to hold the set elements (use an array of Objects).



implementations for all of the interface methods.



a toString method for displaying the contents of the set.
(10%) Provide comments for the class as necessary being sure to document:



how you chose to add elements to the array.



how you chose to remove elements from the array.



how you chose to track the size of the set.



anything else of importance in your implementation choices.



(15%) Write a main method in a le called SetTest.java. Your main method should test your implementation thoroughly. Be sure to document what you are testing at each point.









Assignment 4 Submission Submit on Blackboard:




SetInterface.java



ArraySet.java



SetTest.java



Required Each submitted le should include your name and a statement that this is your own work. This should appear as a comment at the beginning of any code le.

More products