Good start. Now refactor and add the following methods: lcd() - return the true Least Common Denominator. LCD of 1/3 and 2/3 is 3, not 9. reduce() - reduces 2/6 to 1/3 equals() - (new Fraction(1, 3)).equals(new Fraction(2, 6)) should be true inverse() - System.out.println((new Fraction(2, 3)).inverse()); // "3/2" or to make it more interesting, make it printout "1-1/2" (Sorry, I've forgotten all the proper terms for these fractions) Have fun!

As Junilu said, Jesse, you've got a good start going here! I did the same thing as an exercise, and it turned out to be very instructive for me. One thing jumps out at me, though: you may want to do something in the event your user attempts to assign your denominator to zero, instead of letting Java throw its runtime ArithmeticException. Also, a method to add to Junilu's recommended list: public double toDouble() {...}. Good luck, Jess! Art

Conrad Kirby

Ranch Hand

Posts: 178

posted 16 years ago

When reducing, make sure you take into account negative numerator, negative denominator. Good luck!