pnuts.ext
Class Fraction
java.lang.Object
|
+--java.lang.Number
|
+--pnuts.ext.Fraction
- All Implemented Interfaces:
- Numeric, java.io.Serializable
- public class Fraction
- extends java.lang.Number
- implements Numeric
An implementation of fractional number.
This class is an examples of pnuts.lang.Numeric and
pnuts.lang.QuantityFactory.
A sample script to use this class is
here.
- See Also:
- Serialized Form
Constructor Summary |
protected |
Fraction(int num,
int den)
|
protected |
Fraction(java.lang.Number num,
java.lang.Number den)
|
Method Summary |
java.lang.Object |
add(java.lang.Object o)
adds the value of parameter to itself |
int |
compareTo(java.lang.Object o)
compare the object with the parameter. |
java.lang.Object |
divide(java.lang.Object o)
divides itself by the value of parameter |
double |
doubleValue()
|
float |
floatValue()
|
java.lang.Number |
getDenominator()
|
java.lang.Number |
getNumerator()
|
int |
intValue()
|
java.lang.Object |
inverse()
inverts itself |
long |
longValue()
|
static java.lang.Number |
make(int num,
int den)
|
static java.lang.Number |
make(java.lang.Number num,
java.lang.Number den)
|
java.lang.Object |
multiply(java.lang.Object o)
multiplies itself with the value of parameter |
java.lang.Object |
negate()
negates itself by the value of parameter |
java.lang.Object |
subtract(java.lang.Object o)
subtracts the value of parameter from the object |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Number |
byteValue, shortValue |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Fraction
protected Fraction(int num,
int den)
Fraction
protected Fraction(java.lang.Number num,
java.lang.Number den)
make
public static java.lang.Number make(int num,
int den)
make
public static java.lang.Number make(java.lang.Number num,
java.lang.Number den)
getDenominator
public java.lang.Number getDenominator()
getNumerator
public java.lang.Number getNumerator()
intValue
public int intValue()
- Overrides:
intValue
in class java.lang.Number
longValue
public long longValue()
- Overrides:
longValue
in class java.lang.Number
floatValue
public float floatValue()
- Overrides:
floatValue
in class java.lang.Number
doubleValue
public double doubleValue()
- Overrides:
doubleValue
in class java.lang.Number
add
public java.lang.Object add(java.lang.Object o)
- Description copied from interface:
Numeric
- adds the value of parameter to itself
- Specified by:
add
in interface Numeric
subtract
public java.lang.Object subtract(java.lang.Object o)
- Description copied from interface:
Numeric
- subtracts the value of parameter from the object
- Specified by:
subtract
in interface Numeric
multiply
public java.lang.Object multiply(java.lang.Object o)
- Description copied from interface:
Numeric
- multiplies itself with the value of parameter
- Specified by:
multiply
in interface Numeric
divide
public java.lang.Object divide(java.lang.Object o)
- Description copied from interface:
Numeric
- divides itself by the value of parameter
- Specified by:
divide
in interface Numeric
negate
public java.lang.Object negate()
- Description copied from interface:
Numeric
- negates itself by the value of parameter
- Specified by:
negate
in interface Numeric
inverse
public java.lang.Object inverse()
- Description copied from interface:
Numeric
- inverts itself
- Specified by:
inverse
in interface Numeric
compareTo
public int compareTo(java.lang.Object o)
- Description copied from interface:
Numeric
- compare the object with the parameter.
returns one of the followings:
NOT_EQUAL, LEFT_IS_BIGGER, RIGHT_IS_BIGGER, EQUAL
- Specified by:
compareTo
in interface Numeric
toString
public java.lang.String toString()
- Overrides:
toString
in class java.lang.Object