|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.niffty.IntRatio
IntRatio is a mathematical class for representing a rational number. The ratio is alway kept in its simplified form with the denominator positive. You can modify the value of an IntRatio and do arithmetic on it. A Rational, on the other hand, holds a numerator and denominator but is immutable.
Rational
Constructor Summary | |
IntRatio(int numerator,
int denominator)
Creates new IntRatio with the given numerator and denominator. |
|
IntRatio(IntRatio r)
Creates new IntRatio from the given IntRatio. |
|
IntRatio(Rational r)
Creates new IntRatio from the given Rational. |
Method Summary | |
void |
add(IntRatio r)
Set this ratio to this + r |
void |
add(Rational r)
Set this ratio to this + r |
int |
compareTo(java.lang.Object object)
Compare this ratio 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. |
static int |
gcd(int a,
int b)
Return the greatest common denomitator of abs(a) and abs(b). |
int |
getD()
Return the denominator |
int |
getN()
Return the numerator |
void |
set(int numerator,
int denominator)
Set this ratio with the given numerator and denominator. |
void |
set(IntRatio r)
Set the value of this IntRatio to the given IntRatio. |
void |
set(Rational r)
Set the value of this IntRatio to the given Ratioanal. |
void |
sub(IntRatio r)
Set this ratio to this - r |
void |
sub(Rational r)
Set this ratio to this - r |
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 IntRatio(int numerator, int denominator)
java.lang.ArithmeticException
- if denominator is zero.public IntRatio(IntRatio r)
public IntRatio(Rational r)
Method Detail |
public void set(int numerator, int denominator)
java.lang.ArithmeticException
- if denominator is zero.public void set(IntRatio r)
public void set(Rational r)
public int getN()
public int getD()
public void add(IntRatio r)
public void sub(IntRatio r)
public void add(Rational r)
public void sub(Rational r)
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 static int gcd(int a, int b)
public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |