This commit is contained in:
2026-04-23 12:17:56 +03:30
parent 3f09793bdf
commit 1c0ce2ba11
+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) {
int newNumerator = this.numerator * other.denominator + other.numerator * this.denominator;
int newDenominator = this.denominator * other.denominator;
return new Rational(newNumerator, newDenominator);
}
// COMPLETED - Static method: r1 + r2
// COMPLETED - Static method: r1 + r2
public static Rational add(Rational r1, Rational r2) {
return r1.add(r2);
}
@@ -92,7 +92,7 @@ public class Rational {
return null; // Remove this line when implemented
}
// PROVIDED - String representation
// PROVIDED - String representation
@Override
public String toString() {
if (denominator == 1) {
@@ -101,7 +101,7 @@ public class Rational {
return numerator + "/" + denominator;
}
// PROVIDED - Decimal value
// PROVIDED - Decimal value
public double toDouble() {
return (double) numerator / denominator;
}