Package it.unimi.di.prog2.e10
Class RationalNumber
java.lang.Object
it.unimi.di.prog2.e10.RationalNumber
A rational number is an immutable number that can be expressed as the quotient or fraction \( p/q
\) of two
int
s, a numerator \( p \) and a non-zero denominator \( q \).-
Constructor Summary
ConstructorsConstructorDescriptionRationalNumber
(int numerator, int denominator) Creates a new rational number. -
Method Summary
Modifier and TypeMethodDescriptionadd
(RationalNumber other) Returns the sum of this rational number and another one.mul
(RationalNumber other) Returns the product of this rational number and another one.
-
Constructor Details
-
RationalNumber
public RationalNumber(int numerator, int denominator) Creates a new rational number.- Parameters:
numerator
- the numerator.denominator
- the denominator.
-
-
Method Details
-
add
Returns the sum of this rational number and another one.- Parameters:
other
- the other rational number.- Returns:
- the sum of this rational number and
other
.
-
mul
Returns the product of this rational number and another one.- Parameters:
other
- the other rational number.- Returns:
- the product of this rational number and
other
.
-