Example #1
0
  /** *************************************************************************** */
  public Fraction divide(BigInteger temp) // divide returns this / temp
        /** *************************************************************************** */
      {
    if (temp.equals(BigInteger.ZERO))
      throw new ArithmeticException("Divide by zero error: " + this + " / " + temp);

    Fraction returnValue = new Fraction(num, denom.multiply(temp));
    return returnValue.reduce();
  }
Example #2
0
  /** *************************************************************************** */
  public Fraction add(Fraction temp) // addition operators returns this + temp
        /** *************************************************************************** */
      {
    BigInteger Dn = denom.multiply(temp.denom);
    BigInteger Nn1 = num.multiply(temp.denom);
    BigInteger Nn2 = temp.num.multiply(denom);

    BigInteger aNum = Nn1.add(Nn2);

    Fraction returnValue = new Fraction(aNum, Dn);

    return returnValue.reduce();
  }
Example #3
0
 /** *************************************************************************** */
 public Fraction multiply(BigInteger temp) // multiply returns this * temp
       /** *************************************************************************** */
     {
   Fraction returnValue = new Fraction(num.multiply(temp), denom);
   return returnValue.reduce();
 }
Example #4
0
 /** *************************************************************************** */
 public Fraction multiply(Fraction temp) // multiply returns this * temp
       /** *************************************************************************** */
     {
   Fraction returnValue = new Fraction(num.multiply(temp.num), denom.multiply(temp.denom));
   return returnValue.reduce();
 }