Hello!
I'm not new to Java, but my Java knowledge is very poor. My teacher gave me this assignment.
I need help in solving this because I have no idea how to do it.
-----
Create a boolean set class. A boolean set is a set containing only boolean values. The class should contain the following data members:
boolean set[] - This array is the data structure designated to be the set container wherein each index of the array represents the "real" value in the set while the boolean value just indicates if the associated index is an element of the set. So, if set[5] is equal to TRUE, then 5 is an element of the set.
int count - The data member responsible for keeping track of the number of elements/items in the boolean set. So the value of count should be updated upon insertion and deletion.
The class should also define 2 constructors:
public BooleanSet(int size) - where size is to be the size of the set.
public BooleanSet() - where the size of the set is to be 100.
Also, it should define the following methods:
public int cardinality() - returns the number of elements/items currently in the set.
public boolean isMember(int x) - returns TRUE if x is an element in the set, otherwise returns FALSE.
public boolean isEmpty() - returns TRUE if the set is empty, otherwise returns FALSE.
public boolean isFull() - returns TRUE is the set is full, otherwise returns FALSE.
public BooleanSet Union (BooleanSet another) - returns a boolean set that contains the union of this boolean set and BooleanSet another.
public BooleanSet Intersection (BooleanSet another) - returns a boolean set that contains the intersection of this boolean set and BooleanSet another.
-----
For far, this is what I have done.
import java.util.*; class BooleanSet { boolean[] set = new boolean[100]; int count; static ArrayList boolList; public BooleanSet(int size) //where size is to be the size of the set { boolList = new ArrayList(size); } public BooleanSet() //where the size of the set is to be 100 { boolList = new ArrayList(100); } public int cardinality() //returns the number of elements currently in the set { count = boolList.size(); return count; } public boolean isMember(int x) //returns true if x is an element in the set, otherwise returns false { return boolList.contains(x); } public static boolean isEmpty() //returns true if the set is empty, otherwise returns false { return boolList.isEmpty(); } public boolean isFull() //returns true is the set is full, otherwise returns false { if (!(boolList.isEmpty())) return true; else return false; } /*public BooleanSet Union (BooleanSet another) //returns a boolean set that contains the union of this boolean set and BooleanSet another { } public BooleanSet Intersection (BooleanSet another) //returns a boolean set that contains the intersection of this boolean set and BooleanSet another { }*/ public static void main(String[] args) { System.out.println("This is a boolean set."); BooleanSet newSet = new BooleanSet(2); boolList.add(0,54); boolList.add(1,10); boolList.add(2,3); boolList.add(3,286); boolList.add(4,97); System.out.println(boolList); isEmpty(); } }