/** * (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; }
/** * (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; }
/** * (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; }
/** * (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; }