Using java: Your task is to implement a class, IntegerSet, that contains only integers, given the specification below.   public class IntegerSet {               // Hint: probably best to use an array list. You will need to do a little research               private List set = new ArrayList();                 // Default Constructor               public IntegerSet() {               }                 // Clears the internal representation of the set public void clear() {…};   // Returns the length of the set public int length() {…}; // returns the length   /*               * Returns true if the 2 sets are equal, false otherwise; * Two sets are equal if they contain all of the same values in ANY order. */ public boolean equals(IntegerSet b) {…};   // Returns true if the set contains the value, otherwise false public boolean contains(int value) {…};      // Returns the largest item in the set; Throws a IntegerSetException if the set is empty public int largest() {…};   // Returns the smallest item in the set; Throws a IntegerSetException if the set is empty public int smallest() IntegerSetException {…};                 // Adds an item to the set or does nothing it already there                 public void add(int item) {…}; // adds item to the set or does nothing if it is in set                 // Removes an item from the set or does nothing if not there public void remove(int item) {…};   // Set union public void union(IntegerSet intSetb) {…};   // Set intersection public void intersect(IntegerSet intSetb) {…};   // Set difference, i.e., s1 –s2 public void diff(IntegerSet intSetb); // set difference, i.e. s1 - s2   // Returns true if the set is empty, false otherwise boolean isEmpty();   // Return String representation of your set public String toString() {…};     // return String representation of your set }   Below is a sample of how your driver should look. Your driver contains your main method and its primary function is to test your IntegerSet class. Every method in IntegerSet should be sufficiently tested and your output easy to read. Below is a small example of the granularity of how your output should look. Each operation on a method should show the contents of your IntegerSet before and after each operation. Part of your grade on this assignment is how expressive your output is. … IntegerSet set1 = new IntegerSet(); set1.add(1); set1.add(2); set1.add(3);   System.out.println(“Value of Set1 is:” + set1.toString()); System.out.println(“Smallest value in Set1 is:” + set1.smallest()); System.out.println(“Largest value in Set1 is:” + set1.largest());   IntegerSet set2 = new IntegerSet(); set2.add(4); set2.add(5);   System.out.println(“Union of Set1 and Set2”); System.out.println(“Value of Set1 is:” + set1.toString()); System.out.println(“Value of Set2 is:” + set2.toString()); set1.union(set2);          // union of set1 and set2 System.out.println(“Result of union of Set1 and Set2”); set1.toString();              // result of union of set1 and set2     The above format is just a template to use. At the end of the day your output should be an indicator that your program works for ALL methods in IntegerSet. You should create Driver.java that contains all of your test code.

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

Using java:

Your task is to implement a class, IntegerSet, that contains only integers, given the specification below.

 

public class IntegerSet {

              // Hint: probably best to use an array list. You will need to do a little research

              private List<Integer> set = new ArrayList<Integer>();

 

              // Default Constructor

              public IntegerSet() {

              }

 

              // Clears the internal representation of the set

public void clear() {…};

 

// Returns the length of the set

public int length() {…}; // returns the length

 

/*

              * Returns true if the 2 sets are equal, false otherwise;

* Two sets are equal if they contain all of the same values in ANY order.

*/

public boolean equals(IntegerSet b) {…};

 

// Returns true if the set contains the value, otherwise false

public boolean contains(int value) {…};   

 

// Returns the largest item in the set; Throws a IntegerSetException if the set is empty

public int largest() {…};

 

// Returns the smallest item in the set; Throws a IntegerSetException if the set is empty

public int smallest() IntegerSetException {…};

 

              // Adds an item to the set or does nothing it already there  

              public void add(int item) {…}; // adds item to the set or does nothing if it is in set

 

              // Removes an item from the set or does nothing if not there

public void remove(int item) {…};

 

// Set union

public void union(IntegerSet intSetb) {…};

 

// Set intersection

public void intersect(IntegerSet intSetb) {…};

 

// Set difference, i.e., s1 –s2

public void diff(IntegerSet intSetb); // set difference, i.e. s1 - s2

 

// Returns true if the set is empty, false otherwise

boolean isEmpty();

 

// Return String representation of your set

public String toString() {…};     // return String representation of your set

}

 

Below is a sample of how your driver should look. Your driver contains your main method and its primary function is to test your IntegerSet class. Every method in IntegerSet should be sufficiently tested and your output easy to read. Below is a small example of the granularity of how your output should look. Each operation on a method should show the contents of your IntegerSet before and after each operation. Part of your grade on this assignment is how expressive your output is.

IntegerSet set1 = new IntegerSet();

set1.add(1);

set1.add(2);

set1.add(3);

 

System.out.println(“Value of Set1 is:” + set1.toString());

System.out.println(“Smallest value in Set1 is:” + set1.smallest());

System.out.println(“Largest value in Set1 is:” + set1.largest());

 

IntegerSet set2 = new IntegerSet();

set2.add(4);

set2.add(5);

 

System.out.println(“Union of Set1 and Set2”);

System.out.println(“Value of Set1 is:” + set1.toString());

System.out.println(“Value of Set2 is:” + set2.toString());

set1.union(set2);          // union of set1 and set2

System.out.println(“Result of union of Set1 and Set2”);

set1.toString();              // result of union of set1 and set2

 

 

The above format is just a template to use. At the end of the day your output should be an indicator that your program works for ALL methods in IntegerSet. You should create Driver.java that contains all of your test code.

Expert Solution
steps

Step by step

Solved in 4 steps with 7 images

Blurred answer
Knowledge Booster
Arrays
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