For this homework you will implement a simple **generic Set class**. That is, you will implement a `class Set<T>`

using Java's `ArrayList`

as the data member that holds the values.

A set is defined as a collection of elements (in our case, all of the same type) such that every element appears at most once in the collection. The methods your `Set<T>`

must implement are:

`Set()`

the constructor takes no arguments and creates an empty set.`String toString()`

returns a string with all the elements of this set in printed form, as usual.`void add(T x)`

adds element`x`

to the set. If`x`

is already in the set then it does nothing.`boolean contains(T x)`

returns true if the set contains the element`x`

, false otherwise.`void add(Set<T> other)`

adds the complete contents of the set`other`

to this set.`void subtract(Set<T> other)`

removes every element of`other`

that is in this set.`boolean isSubset(Set<T> other)`

returns true if and only if this set is a subset of`other`

, that is, if all the elements in this set are also contained in`other`

.

You will also implement some test cases in your `main()`

to ensure that your class works correctly. This homework is due on **Tuesday, November 24 @noon**.

## No comments:

Post a Comment