Question: Exercise 4 - Boolean and Arrays A set is an unordered collection of objects with no duplicate elements. In this program we consider sets whose

 Exercise 4 - Boolean and Arrays A set is an unordered

Exercise 4 - Boolean and Arrays A set is an unordered collection of objects with no duplicate elements. In this program we consider sets whose elements are decimal digits: 0,1,2,3,4,5,6,7,8, or 9. The cardinality of a set of is the number of elements in it. For example, {5, 2, 0} and {1, 2, 5,9} are sets with cardinality 3 and 4 respectively. The union of two sets (U) is a set containing elements that appear in either of the two sets. The intersection () of two sets is a set containing elements that appear in both sets. If we refer to the sets above as A and B, then A U B = {5, 2, 0, 1,9} and AB-2,5. A set can be modeled as an array of ten booleans that indicate whether a digit is in the set or not. For example the set {5, 2,0} above may be represented by: true false false false true false false false false 0 1 2 3 4 5 6 7 8 9 Write a java program, Set.java that implements the following methods: true public static boolean[createSet(Strings) 1/ returns a set given a string as parameter, e.g., "611" returns the array equivalent to the set {6, 1} public static int cardinality(boolean[] set) 1/ returns the number of elements in set public static boolean inSet(boolean() set, int d) // is the digit d in the set? public static void addElement(boolean[] set, int d) // adds the digit d to the set (if not already in it) public static boolean equals(boolean[] set1, boolean[] set2) // does set and set2 have the same elements? public static boolean[] union(boolean[] set1, boolean[] set2) // returns the union of set! and set2 public static boolean[] intersect(boolean[] set1, boolean[] set2) // returns the intersection of set and set2 public static String toString(boolean[] set) Il returns a string representation of set, e.g., {1,2,3} public static boolean[] multiUnion(boolean[](sets) 1/ returns the union of all sets, i.e., sets[0] U... U sets/sets.length - 1] Your class should include a main() method that tests all the above methods

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!