Overview | Package | Class | Tree | Deprecated | Index | Help | |||
PREV CLASS | NEXT CLASS | FRAMES | NO FRAMES | ||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
RealNumber
interface by
offering narrowed numeric computations for rational numbers.
All rational values can be written as a fraction x/y, where both x and y are integer numbers.
RationalNumber
derivates must obey these rules:
Some RationalNumber
numeric computations are narrowed
compared to their more general RealNumber
equivalents. For
instance, adding two rational numbers will result in a rational number.
The computations concerned are:
add(RationalNumber)
--
adding two rational numbers
will result in another rational numbersubtract(RationalNumber)
--
subtracting one rational number from another
will result in a rational numbermultiply(RationalNumber)
--
multiplying two rational numbers
will result in another rational numberdivide(RationalNumber)
--
dividing one rational number by another
will result in a rational numberpow(IntegerNumber)
--
raising a rational number to an integer power
will result in a rational number
Method Summary | |
RationalNumber | add(RationalNumber n)
Computes this+n, where n is a rational number. |
int | compareTo(RationalNumber n)
|
RationalNumber | divide(RationalNumber n)
Computes this/n, where n is a rational number. |
IntegerNumber | getDenominator()
Returns the denominator of this fraction. |
IntegerNumber | getNumerator()
Returns the numerator of this fraction. |
RationalNumber | multiply(RationalNumber n)
Computes this*n, where n is a rational number. |
RationalNumber | pow(IntegerNumber n)
Computes this**n, where n is an integer number. |
RationalNumber | subtract(RationalNumber n)
Computes this-n, where n is a rational number. |
Method Detail |
public int compareTo(RationalNumber n) throws java.lang.IllegalArgumentException
public RationalNumber add(RationalNumber n) throws java.lang.IllegalArgumentException
n
- the number to add to this.null
.public RationalNumber subtract(RationalNumber n) throws java.lang.IllegalArgumentException
n
- the number to subtract from this.null
.public RationalNumber multiply(RationalNumber n) throws java.lang.IllegalArgumentException
n
- the number to multiply this by.null
.public RationalNumber divide(RationalNumber n) throws java.lang.IllegalArgumentException, java.lang.ArithmeticException
n
- the number to divide this by.null
.public RationalNumber pow(IntegerNumber n)
n
- the exponent.null
.public IntegerNumber getNumerator()
public IntegerNumber getDenominator()
Overview | Package | Class | Tree | Deprecated | Index | Help | |||
PREV CLASS | NEXT CLASS | FRAMES | NO FRAMES | ||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |