The specifications seem pretty good to me. They mean Set as in "Set Theory". One way to represent a set of integers, albeit inefficient from a storage point of view, is to use an array of booleans. This is a perfectly reasonable exercise.
Clearly it would be better to use Set<Integer>
for this project, but that would be missing the point. This is a programming exercise that is fun.
As always, break this down into manageable parts. I would:
- Create the class
- Write the constructor. This will lead you to the proper member variables.
- Write the addElement method
Those things should be pretty easy and perhaps you will gain more insight. Once you have that work on the union and intersection methods. If you still have trouble, check back here!
Keep in mind if you add the value 3, to the set twice, it will only be in the set once. (Definition of sets). So your method will look something like this (keep in mind this is not the 100% correct definition):
public void addElement(int element) {
myArray[element] = true;
}
So when you call addElement(3);
a second or third time, it does not change the state of the set as is proper.