public class Rational
extends java.lang.Object
Constructor and Description |
---|
Rational()
The default constructor for objects of class Rational.
|
Rational(int n,
int d)
The alternate constructor for objects of class Rational.
|
Modifier and Type | Method and Description |
---|---|
Rational |
add(Rational other)
Add two rational numbers
|
Rational |
divide(Rational other)
Divide this rational number r by another one t
|
int |
getDenominator()
Get the value of the Denominator
|
int |
getNumerator()
Get the value of the Numerator
|
Rational |
invert()
Invert a rational number r
|
Rational |
multiply(Rational other)
Multiply two rational numbers
|
Rational |
negate()
Negate a rational number r
|
Rational |
subtract(Rational other)
Subtract a rational number t from this one r
|
public Rational()
public Rational(int n, int d)
n
- The numerator of the rational number.d
- The denominator of the rational number.public int getNumerator()
public int getDenominator()
public Rational negate()
public Rational invert()
public Rational add(Rational other)
other
- the second argument of the addpublic Rational subtract(Rational other)
other
- the second argument of subtractpublic Rational multiply(Rational other)
other
- the second argument of multiply