Re: program of sets
On Wed, 10 Oct 2007 09:02:06 -0700, sdlt85@gmail.com wrote:
Hi,
I need to do a program of sets but I don't know how to start, can
some
one give me a hit.
Hit: Elvis Presley - Heartbreak Hotel.
Hint: follows :)
Here is the description:
I need to create a class IntegerSet.
public class IntegerSet {...}
Each IntegerSet object can hold
integers in the range 0-100. The set is represented by an array of
Boolean values.
private boolean[] mElements = new boolean[101]
Array element a [i] is true, if integer i is in the
set. Array element a [j] is false, if integer j is not in the set.
Standard construction for a set.
The no-argument (default) constructor initializes the array to the
"empty set" (i.e., a set whose array representation).
You seem to have left out something here, it probably read something
like: "a set whose array representation comprises all false values".
public IntegerSet() {...}
I need to use an overloaded constructor to create an IntegerSet
object
initialized with a set of integer values.
Do you know what "overloaded" means in this context? If not then read
your Java book, google or ask your instructor.
How are the integer values to be passed to the constructor? Two
possibilities are:
public IntegerSet(int[] values) {...}
public IntegerSet(IntegerSet values) {...}
You can either write both, or ask your instructor which one is
required.
Also I need to provide the method 'union',
The details of these methods will depend on whether you decide your
implementation of IntegerSet is immutable or not. I give some
possible partial method signatures below:
public IntegerSet union(...) {...}
'intersection',
public IntegerSet intersection(...) {...}
'insert Element',
public IntegerSet insertElement(...) {...}
'delete Element',
public IntegerSet deleteElement(...) {...}
'to SetString' and
public String toSetString() {...}
'Equal to'
public boolean equalTo(...) {...}
within class IntegerSet.
Write these methods one at a time, starting with the constructors.
Test each method as soon as you have written it. Do toSetString()
method early since that will be useful in testing - it gives you an
easy way to see what is actually in your set, as opposed to what you
thought was in it.
This is what I have so far:
public class UniversalSet
Why "UniversalSet" rather than "IntegerSet"? The question asks for
"IntegerSet". When you are given a specification, you need to follow
it.
{
public static void main(String[] args)
{
System.out.println("Welcome to the Universal Set");
IntegerSet A = new IntegerSet();
You should get a compile error here. Also use a meaningful variable
name, not just 'A'. Something like "myIntegerSet" is better.
}
}
Thanks
rossum