|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.ObjectFraction
public class Fraction
The Fraction class implements fractions.
Each fraction is a pair numerator/denominator of longs
in simplified form, i.e. gcd(numerator,denominator) = 1
| Constructor Summary | |
|---|---|
Fraction()
Default constructor, constructs 0 as fraction 0/1 |
|
Fraction(long a)
Constructs Fraction object from a long |
|
Fraction(long num,
long denom)
Constructor with two long argument num and denom, constructs the fraction num/denom and simplifies it. |
|
| Method Summary | |
|---|---|
void |
add(Fraction r)
Adds fraction r to this fraction and simplifies result. |
java.lang.Object |
clone()
clones this fraction by implementing Cloneable |
double |
doubleValue()
Returns the double value of this fraction. |
boolean |
equals(Fraction r)
Checks equality with other fraction r. |
long |
getDenominator()
Get the denominator of this fraction |
long |
getNumerator()
Get the nominator of this fraction |
void |
multiply(Fraction r)
Multiplies this fraction with other fraction r and simplifies the result. |
java.lang.String |
toString()
Returns a string representation of this fraction. |
| Methods inherited from class java.lang.Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Fraction()
public Fraction(long a)
a - yields the fraction a/1
public Fraction(long num,
long denom)
throws java.lang.ArithmeticException
num - the numeratordenom - the denominator
Throws ArithmeticException if
denom == 0
java.lang.ArithmeticException| Method Detail |
|---|
public java.lang.String toString()
toString in class java.lang.Objectpublic double doubleValue()
public boolean equals(Fraction r)
r - the fraction to be compared with
true if this fraction equals r.public long getNumerator()
public long getDenominator()
public void multiply(Fraction r)
r - the fraction to be multiplied with.public void add(Fraction r)
r - the fraction to be added.public java.lang.Object clone()
clone in class java.lang.Object
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||