CSC297.Java, 2003F: A Rational Class Admin: * We'll discuss your proposed methods in a moment. * Don't forget, Friday is the deadline for add/drop. Topics: * A Rational Class * Lessons Learned We should be able to simplify rational numbers Rational rat = new Rational(2,4); rat.simplify() // Option 1 Rational.simplify(rat); // Option 2 // Option 3: Rationals are only stored in simplified form // We choose option 3 Output as a string Output in decimal format // Option 1: Print it // Option 2: Return a double/real // Option 3: Return a string for the decimal // We select option 2 Rational half = new Rational(1,2); double x = half.doubleValue(); Arithmetic operations Rational a = new Rational(...); Rational b = new Rational(...); Rational c = a.times(b); // Option 1 Rational d = Rational.multiply(a,b); // Option 2 // We select option 2 Object Fields long numerator long denominator Class Fields Constructors Client provides numerator and denominator Client provides real number and we figure out the corr. rational. Object Methods * simplify (internal method, not available to outside world) * String toString() * doubleValue, shortValue, floatValue, ... Class Methods * multiply * divide * add * subtract Lessons learned: * When referring to fields, you should always give the name of the object. * If you have no other name (i.e., if it's in "the current object"), use this * If you use /** ... */ style comments, you can create nifty documentation with javadoc. * E.g. javadoc *.java * E.g. javadoc Foo.java Bar.java * When you treat an object like a string, Java automatically calls the "toString" method. Your goal for Wednesday: Finish the Rational class (and extend the TestRational class to include your other stuff). If you can't figure out how to write the other constructor, that's okay, we'll discuss it.