public class Rational
extends java.lang.Object
Modifier and Type | Field | Description |
---|---|---|
protected int |
denominator |
|
protected int |
numerator |
|
static Rational |
ZERO |
Constructor | Description |
---|---|
Rational() |
|
Rational(int numerator,
int denominator) |
Creates Rational instance with the given numerator and denominator.
|
Modifier and Type | Method | Description |
---|---|---|
int |
denominator() |
Returns the denominator.
|
int |
numerator() |
Returns the numerator.
|
Rational |
plus(Rational r) |
Returns a new Rational instance, which is the result of adding the given
Rational to this Rational.
|
protected void |
simplify() |
Simplify the rational.
|
Rational |
times(Rational r) |
Returns a new Rational instance, which is the result of multiplying this
Rational by the given Rational.
|
java.lang.String |
toString() |
protected int numerator
protected int denominator
public static final Rational ZERO
public Rational()
public Rational(int numerator, int denominator)
public int numerator()
public int denominator()
public Rational times(Rational r)
public Rational plus(Rational r)
protected void simplify()
public java.lang.String toString()
toString
in class java.lang.Object