You may work individually or in pairs.
Problem 14 on p. 239 specifies methods and behavior of a set. Implement and test a class Set<E> with the following differences from the one described in the book:
Set<E>
, where E is
the type of the elements in the set. For instance, you would be able
to create Set<String>
or Set<Integer>
. All methods that take or
return elements should take or return objects of type E.ArrayList
, and not an array, to
store the elements. createSet
just write a
constructor that creates an empty set, i.e. you should be able to
create a set of strings as new Set<String>()
isEmpty()
that returns true if this set is empty and
false otherwise,size()
that returns the size of the set (the number
of elements)add(E element)
adds an element to a set if it's not
already present.contains(E element)
returns true if an element is present in
the set and false otherwise.union(Set<E> otherSet)
returns a
new Set<E>
that is the
union of this set and the other set. Make sure you follow definition
of set union.intersection(Set<E> otherSet)
returns a
new Set<E>
that is the
intersection of this set and the other set. Make sure you follow definition
of set intersection.removeAll()
removes all elements from the set.Submit your Set class and your test class. The quality of your testing will be a part of the grade.
Submit the java file(s) with your testing code by e-mail to me. The subject of the message must be 2101 Problem set 4. Make sure to CC your group partner(s) if any.