Update src/main/java/Rational/Rational.java

This commit is contained in:
2026-04-23 08:49:20 +00:00
parent 3f09793bdf
commit 0bd31c6f76
+4 -4
View File
@@ -39,14 +39,14 @@ public class Rational {
} }
} }
// COMPLETED - Instance method: this + other // COMPLETED - Instance method: this + other
public Rational add(Rational other) { public Rational add(Rational other) {
int newNumerator = this.numerator * other.denominator + other.numerator * this.denominator; int newNumerator = this.numerator * other.denominator + other.numerator * this.denominator;
int newDenominator = this.denominator * other.denominator; int newDenominator = this.denominator * other.denominator;
return new Rational(newNumerator, newDenominator); return new Rational(newNumerator, newDenominator);
} }
// COMPLETED - Static method: r1 + r2 // COMPLETED - Static method: r1 + r2
public static Rational add(Rational r1, Rational r2) { public static Rational add(Rational r1, Rational r2) {
return r1.add(r2); return r1.add(r2);
} }
@@ -92,7 +92,7 @@ public class Rational {
return null; // Remove this line when implemented return null; // Remove this line when implemented
} }
// PROVIDED - String representation // PROVIDED - String representation
@Override @Override
public String toString() { public String toString() {
if (denominator == 1) { if (denominator == 1) {
@@ -101,7 +101,7 @@ public class Rational {
return numerator + "/" + denominator; return numerator + "/" + denominator;
} }
// PROVIDED - Decimal value // PROVIDED - Decimal value
public double toDouble() { public double toDouble() {
return (double) numerator / denominator; return (double) numerator / denominator;
} }