CIT 594 Assignment
1: Fractions Spring 2008, David Matuszek |

- To get you started with NetBeans 6.0
- To get you started with JUnit 4
- To improve your javadoc skills

I am providing you with a "fractions" class. Copy this class into NetBeans 6.0, add javadoc comments to it (including comments for private elements), and write a complete set of JUnit 4 tests for it (including for the constructor).

The class is complete, except that it does not throw exceptions when it should (hint: division by zero is illegal). Fix this (and test the fix).

package fraction; public class Fraction { private int numerator; private int denominator; public Fraction(int numerator, int denominator) { this.numerator = numerator; this.denominator = denominator; normalizeSigns(); reduceToLowestTerms(); } public Fraction add(Fraction that) { return new Fraction(this.numerator * that.denominator + that.numerator * this.denominator, this.denominator * that.denominator); } public Fraction subtract(Fraction that) { return new Fraction(this.numerator * that.denominator - that.numerator * this.denominator, this.denominator * that.denominator); } public Fraction multiply(Fraction that) { return new Fraction(this.numerator * that.numerator, this.denominator * that.denominator); } public Fraction divide(Fraction that) { return new Fraction(this.numerator * that.denominator, this.denominator * that.numerator); } @Override public boolean equals(Object obj) { Fraction that = (Fraction) obj; return this.numerator * that.denominator == this.denominator * that.numerator; } @Override public String toString() { return numerator + "/" + denominator; } private void normalizeSigns() { if (denominator < 0) { numerator = -numerator; denominator = -denominator; } } private void reduceToLowestTerms() { int gcd = greatestCommonDivisor(numerator, denominator); if (gcd > 1) { numerator /= gcd; denominator /= gcd; } } static int greatestCommonDivisor(int a, int b) { while (b != 0) { int temp = b; b = a % b; a = temp; } return a; } }

- The quality of your javadoc. It should be correct and complete, should be in the right form, should address the correct audience, and should be reasonably grammatical (we will make allowances for non-native English speakers). In short, it should follow all the rules presented in class.
- The completeness of your JUnit tests. We will run your tests against a version of the Fraction class that has several errors in it. These will be "reasonable" errors, not weird artificial ones. You will lose points for any error that your tests do not catch. This means that you need to think carefully about "edge" cases, for example, those involving zero, or mixed positive and negative numbers.

Zip the complete project and submit via Blackboard before midnight Wednesday, January 23.