From the textbook, do Exercise 8.16, noting the extra instructions
below. Also, add features into the Fraction class (the example discussed
in lecture) as described below.
Filenames should be
1) For problem 16, change the name of the method toSetString to toString. Here are the 1 constructor and 6 method signatures:
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()Note that, besides the constructor, insertElement and deleteElement are the only methods that can change the calling object. The union and intersection methods should return a brand new set.
2) Start with this copy of the Fraction class, which was discussed in lecture class (download from the link here), and add the following features:
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. Also, the arithmetic methods should each return the result as a fraction in simplified format
Fraction simplify(); Fraction add(Fraction f); Fraction subtract(Fraction f); Fraction multiply(Fraction f); Fraction divide(Fraction f);
Here's the HW5Tester.java file. This contains tests for both the IntegerSet and the Fraction classes.
myers@diablo:programs/sum04/a5>java HW5Tester 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 // Fixed mistake in writeup 75/175 / 0/1 = 0/1
Pack all your files, class files and source code, into a fully runnable JAR file called hw5.jar. The main program that the jar file should execute is my HW5Tester program (unchanged). I should be able to run the HW5Tester main() program from your jar file with the command:
java -jar hw5.jar
E-mail this jar file to me (myers@cs.fsu.edu) by the due date. Your
e-mail subject should be HW5-SUBMIT. Include your name and section
in the e-mail body. Please only submit ONCE, unless you make a mistake
and need to correct it (before the due date) -- and minimize this. Only
the last submission will be graded.