Sev Marc wrote:Write a Java program (FractionDemo) with the main method) that, using the class Fraction, performs operations on fractions.
If you were to follow these instructions, your program should look something like this:
The format string passed to printf() on lines 9 and 10 will call the
Fraction.toString() method that you are instructed to override.
Note also that private members of a class instance are directly accessible by other instances of the same class, so you really don't need to access the numerator and denominator fields via getters in the implementations of the add, subtract, etc. methods. There may be those who object to that approach and insist that
you should use getters to access private members but I would cite Joshua Bloch's recipe for equals() and note that he takes advantage of this ability to arguably break encapsulation of other instances of the same class; if it's good enough for Joshua Bloch, it's good enough for me.