public class Fraction { private int n; // numerator private int d; // denominator // Constructors public Fraction () { // default n=0; d=1; } public Fraction (int n, int d) { // with parameters this.n = n; // this is the member variable this.d = d; } public Fraction (Fraction toCopy) { // Copy Constructor this.n = toCopy.n; this.d = toCopy.d; } // Methods public void set (int n, int d) { this.n = n; this.d = d; } public Fraction add (Fraction f) { n = n*f.d + f.n*d; d = d*f.d; return this; // returns the active instance } /* implement the missing methods for * subtraction, multiply and divide */ // std method for conversion to string (see API: java.lang.Object) public String toString () { return ("Fraction("+n+"/"+d+")"); } }