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
 * Precondition: None
 * Postcondition: None
 * @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 )
{
	//create a new fraction object, by invoking its constructor with the required arguments.
	//the first argument will be the product of the numerators of the calling object and the object passed as argument.
	//the second argument will be the product of denominators of calling object and the object passed as the argument.
}

Testing

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