Starting from:
$30

$24

Homework # 7 Java Inheritance and Generics Solution

In this homework, you will write a generic class hierarchy for sets and maps for Java.




GTUSetInt<T is a Java interface with the following methods.




empty




Test whether container is empty




size




Return container size




max_size




Return maximum size




insert




Insert element, throws exception InvalidParameterException if the element is already in the set




intersection




The returned set is the intersection of this set and the given set.




erase




Erase element




clear




Clear all content




find




Get iterator to element




count




Count elements with a specific value




begin




Return iterator to beginning




end




Return iterator to end




The class GTUSet<T implements the GTUSetInt interface. It will keep its data using Java arrays.

Do not use any Java Collection classes. It implements the intersection method as follows:




intersection




GTUSetInt<T intersection(GTUSetInt<T)







The returned set is the intersection of this set and the given set.

The class GTUMap<K, V extends from GTUSet< javafx.util.Pair <K, V and implements the following extra method




at




Access element




V at(K k)







If k matches the key of an element in the set, the method returns a reference to its mapped value.







The class GTUIterator implements the following methods








boolean
hasNext()


































Returns true if this list iterator has more elements when traversing the list in the forward direction.
























boolean




hasPrevious()


































Returns true if this list iterator has more elements when traversing the list in the reverse direction.




T


next()






























Returns the next element in the list and advances the cursor position.




T


previous()




























Returns the previous element in the list and moves the cursor position backwards.




























Write your driver class to test the all the classes and all of their methods.




Notes




Submit your nicely produced Javadoc documents with your homework.
Do not forget to test the thrown exceptions

More products