Build a class called IntegerSet, which is based on
Exercises 8.13 and 8.14 from the textbook, noting more specific
instructions below. Also, add features into the Fraction class (the
example discussed in lecture) as described below.
Filenames should be
Short summary of exercise (paraphrased from the book), along with extra instructions:
IntegerSet() public IntegerSet union(IntegerSet iSet) public IntegerSet intersection(IntegerSet iSet) public IntegerSet insertElement(int data) public IntegerSet deleteElement(int data) public boolean isEqualTo(IntegerSet iSet) public String toString()
f1.add(f2) // means f1 + f2 f1.subtract(f2) // means f1 - f2In divide, if an attempt is made to divide by a fraction with the value 0, default the result to 0/1. (Such division is actually undefined. 0/1 is not the "true" result, but we need to return something from this method).
public Fraction simplify() public Fraction add(Fraction f) public Fraction subtract(Fraction f) public Fraction multiply(Fraction f) public Fraction divide(Fraction f)
Here's the HW2Tester.java file. This contains some tests for both the IntegerSet and the Fraction classes.
myers@diablo:~>java HW2Tester After set1.insertElement(10), set1 = 0 2 8 10 default IntegerSet is = --- set1 = 0 2 4 6 8 10 12 95 100 set2 = 0 3 6 9 12 set1.union(set2) = 0 2 3 4 6 8 9 10 12 95 100 set1.intersection(set2) = 0 6 12 set1.deleteElement(2) = 0 4 6 8 10 12 95 100 set1.isEqualTo(set1) = true set1.isEqualTo(set2) = false Fraction tests: 4/6 simplified = 2/3 75/175 simplified = 3/7 -6/17 simplified = -6/17 f1 = 4/6 f2 = 75/175 f3 = -6/17 4/6 + 75/175 = 23/21 4/6 - 75/175 = 5/21 4/6 * 75/175 = 2/7 4/6 / 75/175 = 14/9 75/175 + -6/17 = 9/119 75/175 - -6/17 = 93/119 75/175 * -6/17 = -18/119 75/175 / -6/17 = -17/14 75/175 / 0/1 = 0/1
Pack all your files, class files and source code, into a fully runnable JAR file called hw2.jar. We will discuss how to build this kind of jar in class this week, and the link "Using JAR files" under the "Resources" links on the course content page also has an example of this.
The main program that the jar file should execute is my HW2Tester program (unchanged). I should be able to run the HW2Tester main() program from your jar file with the command:
java -jar hw2.jar
Submit your jar file via the Canvas submission link for
assignment 2.