program of sets
Hi,
I need to do a program of sets but I don't know how to start, can
some
one give me a hit.
Here is the description:
I need to create a class IntegerSet. Each IntegerSet object can hold
integers in the range 0-100. The set is represented by an array of
Boolean values. Array element a [i] is true, if integer i is in the
set. Array element a [j] if j is false, if integer is not in the set.
The no-argument (default) constructor initializes the array to the
"empty set" (i.e., a set whose array representation).
I need to use an overloaded constructor to create an IntegerSet
object
initialized with a set of integer values.
Also I need to provide the method 'union', 'intersection', 'insert
Element', 'delete Element', 'to SetString' and 'Equal to' within
class
IntegerSet.
This is what I have so far:
public class IntegerSet
{
private static final int SIZE = 101;
private boolean[] a = new boolean[SIZE];
public IntegerSet() { } // Note it's no-arg., but *not* default
constructor!.
public IntegerSet(int... ints)
{
for(int i : ints)
a[i] = true;
}
public IntegerSet union(IntegerSet other)
{
IntegerSet res = new IntegerSet();
for(int i=0; i<SIZE; i++)
System.out.printf("%5d%8d\n", i, a[i]);
return res;
}
}
public class UniversalSet
{
public static void main(String[] args)
{
System.out.println("Welcome to the Universal Set");
IntegerSet A = new IntegerSet();
}
}
Thanks.