mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-12-19 07:00:35 +08:00
@@ -21,11 +21,8 @@ public record ADTFraction(int numerator, int denominator) {
|
||||
* @return A new {@code ADTFraction} containing the result of the operation
|
||||
*/
|
||||
public ADTFraction plus(ADTFraction fraction) {
|
||||
var numerator =
|
||||
this.denominator *
|
||||
fraction.numerator +
|
||||
this.numerator *
|
||||
fraction.denominator;
|
||||
var numerator
|
||||
= this.denominator * fraction.numerator + this.numerator * fraction.denominator;
|
||||
var denominator = this.denominator * fraction.denominator;
|
||||
return new ADTFraction(numerator, denominator);
|
||||
}
|
||||
@@ -64,7 +61,8 @@ public record ADTFraction(int numerator, int denominator) {
|
||||
/**
|
||||
* Calculates the result of the fraction.
|
||||
*
|
||||
* @return The numerical result of the division between {@code numerator} and {@code denominator}
|
||||
* @return The numerical result of the division between {@code numerator} and {@code
|
||||
* denominator}
|
||||
*/
|
||||
public float value() {
|
||||
return (float) this.numerator / this.denominator;
|
||||
|
||||
Reference in New Issue
Block a user