implement multiply static and instance method
This commit is contained in:
@@ -67,17 +67,20 @@ public class Rational {
|
|||||||
return r1.subtract(r2);
|
return r1.subtract(r2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Instance method - this * other
|
// COMPLETED - Instance method - this * other
|
||||||
// Formula: (a/b) * (c/d) = (a*c) / (b*d)
|
|
||||||
public Rational multiply(Rational other) {
|
public Rational multiply(Rational other) {
|
||||||
// YOUR CODE HERE
|
int newNumerator = this.numerator * other.numerator;
|
||||||
return null; // Remove this line when implemented
|
int newDenominator = this.denominator * other.denominator;
|
||||||
|
|
||||||
|
Rational result = new Rational(newNumerator, newDenominator);
|
||||||
|
result.simplify();
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Static method - r1 * r2
|
// COMPLETED - Static method - r1 * r2
|
||||||
public static Rational multiply(Rational r1, Rational r2) {
|
public static Rational multiply(Rational r1, Rational r2) {
|
||||||
// YOUR CODE HERE
|
return r1.multiply(r2);
|
||||||
return null; // Remove this line when implemented
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Instance method - this / other
|
// TODO: Instance method - this / other
|
||||||
|
|||||||
Reference in New Issue
Block a user