Assignment #5

Due: Monday, June 21

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

Note that this filename starts with a capital letter. Please make sure your filenames match mine exactly.

Instructions

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:


Testing

I've provided a file to help you get started with testing. This is not a comprehensive set of tests (so you'll want to try some of your own). However, this will get you started. And you do need to include the HW5Tester class (unchanged) in your jar file when you submit. See instructions at the bottom.

Here's the HW5Tester.java file. This contains tests for both the IntegerSet and the Fraction classes.

Here's the sample run

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

Submitting:

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.