Creating the multiply method

Another common fraction operation is multiplication. For our Fraction class, we will create a multiply method which takes in another Fraction and returns the product of itself and the incoming Fraction. Like the reciprocal method, instead of altering our Fraction, we will create and return a new Fraction as the result. This is akin to primitive mathematical operations. If we multiply two integers, neither of the integers are altered and a new integer is created.

The numerator of the new Fraction is the product of the calling Fraction's numerator and the argument Fraction's numerator.

The denominator of the new Fraction is the product of the calling Fraction's denominator and the argument Fraction's denominator.

/**
 * Multiples this Fraction by a given Fraction
 * @param otherFraction the Fraction to multiply by
 * @return A Fraction that is the result of multiplying this Fraction by the given Fraction
 */
public Fraction multiply( Fraction otherFraction )
{
	return new Fraction( otherFraction.getNumerator() * this.getNumerator(), otherFraction.getDenominator() * this.getDenominator() );
}

Testing

  1. Un-comment the code in main that prints the product of the two fractions.