Exemple #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)
Exemple #2
0
 // Subtract
 public Fraction subtract(Fraction other) throws Exception {
   return (this.add(other.multiply(new Fraction("-1/1"))));
 }
Exemple #3
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)