Example #1
0
  // Add this rational number to another fraction.
  // note: not simplified
  public Fraction add(Fraction other) throws Exception {
    Fraction ans =
        new Fraction(
            (this.num.multiply(other.denom).add(this.denom.multiply(other.num))),
            this.denom.multiply(other.denom));

    return ans.simplify();
  } // add(fraction)
Example #2
0
 // multiplies this and another fraction
 public Fraction multiply(Fraction mult) throws Exception {
   Fraction ans = new Fraction(this.num.multiply(mult.num), this.denom.multiply(mult.denom));
   return ans.simplify();
 } // multiply(int)