Assignment #2

Due: Mon, Sept 23

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

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

Instructions

IntegerSet

Short summary of exercise (paraphrased from the book), along with extra instructions:

Fraction exercise

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 HW2Tester class (unchanged) in your jar file when you submit. See instructions at the bottom.

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

Here's the sample run

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

Submitting:

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.