Example #1
0
  /**
   * (Subtracts the two fractions)
   *
   * @param (fraction the operation is being applied to)
   * @return (output fraction)
   */
  public Fraction minus(Fraction f) { // subtracts 2 fractions and returns reduce fraction result

    if (f.den != den) {
      f.num *= den;
      num *= f.den;
      f.den *= den;
      den = f.den;
    }

    f.num -= num;
    f.reduce();
    return f;
  }
Example #2
0
  /**
   * (Adds the two fractions)
   *
   * @param (fraction the operation is being applied to)
   * @return (output fraction)
   */
  public Fraction plus(Fraction f) { // adds 2 fractions and returns reduce fraction result

    if (f.den != den) {
      f.num *= den;
      num *= f.den;
      f.den *= den;
      den = f.den;
    }

    f.num += num;
    f.reduce();
    return f;
  }
Example #3
0
 /**
  * (Divides the two fractions)
  *
  * @param (fraction the operation is being applied to)
  * @return (output fraction)
  */
 public Fraction divide(Fraction f) { // divides 2 fractions and returns reduce fraction result
   f.num *= den;
   f.den *= num;
   f.reduce();
   return f;
 }
Example #4
0
 /**
  * (Multiplies the two fractions)
  *
  * @param (fraction the operation is being applied to)
  * @return (output fraction)
  */
 public Fraction times(Fraction f) { // multiplies 2 fractions and returns reduce fraction result
   f.num *= num;
   f.den *= den;
   f.reduce();
   return f;
 }