Question
Using java: Your task is to implement a class, IntegerSet, that contains only integers, given the specification below. public class IntegerSet { // Hint: probably
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
// 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.
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