Create class IntegerSet. Each IntegerSet object can hold integers 0 though n, where n can be different for different sets. The set is represented by an array of booleans. 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. Provide the following methods. Constructor IntegerSet(int n) creates an object with an array of size n with all cells set to false. Method union(IntegerSet set) creates a set that is the set-theoretic union of two existing sets (i.e., an element of the new set’s array is set to true if that element is true in at least one of the existing sets – otherwise, the new set’s element is set to false). Method intersec­tion(IntegerSet set) creates a set which is the set-theoretic intersection of two existing sets (i.e., an element of the new set’s array is set to false if that element is false in at least one of the existing sets – other­wise, the new set’s element is set to true). Method insertElement(int n) inserts a new integer n into a set (by setting a[n] to true). Method deleteElement(int n) deletes integer n (by setting a[n] to false). Method toString() returns a String containing a set as a list of numbers separated by spaces. Include only those elements that are present in the set. Use --- to represent an empty set. Method equals(Object set) determines whether two sets are equal. Both toString() and equals() should redefine the two methods inherited from Object. Write a program to test class IntegerSet. Instan­tiate several IntegerSet objects. Test all your methods.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Create class IntegerSet. Each IntegerSet object can hold integers 0 though n, where n can be different for different sets. The set is represented by an array of booleans. 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.

Provide the following methods.

Constructor IntegerSet(int n) creates an object with an array of size n with all cells set to false.

Method union(IntegerSet set) creates a set that is the set-theoretic union of two existing sets (i.e., an element of the new set’s array is set to true if that element is true in at least one of the existing sets – otherwise, the new set’s element is set to false).

Method intersec­tion(IntegerSet set) creates a set which is the set-theoretic intersection of two existing sets (i.e., an element of the new set’s array is set to false if that element is false in at least one of the existing sets – other­wise, the new set’s element is set to true).

Method insertElement(int n) inserts a new integer n into a set (by setting a[n] to true).

Method deleteElement(int n) deletes integer n (by setting a[n] to false).

Method toString() returns a String containing a set as a list of numbers separated by spaces. Include only those elements that are present in the set. Use --- to represent an empty set.

Method equals(Object set) determines whether two sets are equal.

Both toString() and equals() should redefine the two methods inherited from Object.

Write a program to test class IntegerSet. Instan­tiate several IntegerSet objects. Test all your methods.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education