Question
Create class IntegerSet for which each object can hold integers in the range 0 through 100. A set is represented internally as an array of
Create class IntegerSet for which each object can hold integers in the range 0 through 100. A set is represented internally as an array of ones and zeros. Array element a[i] is 1 if integer i is in the set. Array element a[j] is 0 if integer j is not in the set. It means that the array indices represent the numbers and values (0 or 1) represent that appearance of value or not. Example: if a [3] value = 0, it means that 3 is not in the set. The following must be appeared in the class: An attribute setValues array to save values of set. The default constructor initializes a set to the so-called empty set, i.e., a set whose array representation contains all zeros. A method called public Set unionOfSets (Set s) that creates a third set that is the settheoretic union of two existing sets (i.e., an element of the third sets array is set to 1 if that element is 1 in either or both of the existing sets, and an element of the third sets array is set to 0 if that element is 0 in each of the existing sets). A method called public Set intersectionOfSets (Set s) which creates a third set which is the set theoretic intersection of two existing sets and return the third set (i.e., an element of the third sets array is set to 0 if that element is 0 in either or both of the existing sets, and an element of the third sets array is set to 1 if that element is 1 in each of the existing sets). A method called public void insertElement (int value) that inserts a new integer k into a set (by setting a[k] to 1). A method called public void deleteElement (int value) that deletes integer m (by setting a[m] to 0). A method called public void printSet () that prints a set as a list of numbers separated by spaces. Print only those elements that are present in the set (i.e., their position in the array has a value of 1). Print --- for an empty set. A method called public Boolean isEqualTo (Set s) that determines whether two sets are equal. Provide an additional constructor that receives an array of integers and the size of that array and uses the array to initialize a set object. Note: Each method of the above method takes an object of a set class as a parameter. Now write a main program to test your IntegerSet class with all its methods and create two sets to test your work.
Problem 2 Create class IntegerSet for which each object can hold integers in the range 0 through 100. A set is represented internally as an array of ones and zeros. Array element a[i] is 1 if integer i is in the set. Array element a[i] is 0 if integer j is not in the set. It means that the array indices represent the numbers and values (0 or 1) represent that appearance of value or not. Example: if a [3] value = 0, it means that 3 is not in the set. The following must be appeared in the class: An attribute 'setValues' array to save values of set. The default constructor initializes a set to the so-called empty set," i.e., a set whose array representation contains all zeros. A method called public Set unionOfSets (Set s) that creates a third set that is the set- theoretic union of two existing sets (i.e., an element of the third sets array is set to 1 if that element is 1 in either or both of the existing sets, and an element of the third sets array is set to 0 if that element is in each of the existing sets). A method called public Set intersection OfSets (Set s) which creates a third set which is the set theoretic intersection of two existing sets and return the third set (i.e., an element of the third sets array is set to 0 if that element is O in either or both of the existing sets, and an element of the third sets array is set to 1 if that element is 1 in each of the existing sets). A method called public void insertElement (int value)" that inserts a new integer k into a set (by setting a[k] to 1). A method called public void insertElement int value)" that inserts a new integer k into a set (by setting a[k] to 1). A method called "public void deleteElement(int value)" that deletes integer m (by setting a[m] to 0). A method called "public void printSet " that prints a set as a list of numbers separated by spaces. Print only those elements that are present in the set (i.e., their position in the array has a value of 1). Print --- for an empty set. A method called public Boolean isEqualTo (Set s) that determines whether two sets are equal. Provide an additional constructor that receives an array of integers and the size of that array and uses the array to initialize a set object. Note: Each method of the above method takes an object of a set class as a parameter. Now write a main program to test your IntegerSet class with all its methods and create two sets to test your work
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started