|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.niffty.Rational
A Rational in an immutable object for representing a rational number with a numerator and denominator. The ration is always kept in its simplified form, with the denominator positive. A Rational is immutable. Therefore you can pass a Rational to another method and know that it won't modify it. An IntRatio, on the other hand, can be modified and can do more arithmetic.
IntRatio
Constructor Summary | |
Rational(int numerator,
int denominator)
Creates new Rational with the given numerator and denominator. |
|
Rational(IntRatio r)
Creates new Rational with the numerator and denominator from the given IntRatio. |
Method Summary | |
int |
compareTo(java.lang.Object object)
Compare this Rational to object and return -1 if this is less than object, 1 if this is greater than object, or zero if they are equal. |
double |
doubleValue()
Return numerator/denominator as a double value. |
boolean |
equals(java.lang.Object object)
Return true of the result of compareTo for the object is zero. |
int |
getD()
Return the denominator |
int |
getN()
Return the numerator |
java.lang.String |
toString()
Returns string as "numerator/denominator" |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public Rational(int numerator, int denominator)
public Rational(IntRatio r)
Method Detail |
public int compareTo(java.lang.Object object)
java.lang.ClassCastException
- if object is not an IntRatio or Rational.public boolean equals(java.lang.Object object)
equals
in class java.lang.Object
compareTo(java.lang.Object)
public final double doubleValue()
public java.lang.String toString()
toString
in class java.lang.Object
public final int getN()
public final int getD()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |