Constructor and Description |
---|
Lfraction(long a,
long b)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
clone()
Clone of the fraction.
|
int |
compareTo(Lfraction m)
Comparision of fractions.
|
Lfraction |
divideBy(Lfraction m)
Quotient of fractions.
|
boolean |
equals(java.lang.Object m)
Equality test.
|
Lfraction |
fractionPart()
Extract fraction part of the (improper) fraction
(a proper fraction without the integer part).
|
long |
getDenominator()
Public method to access the denominator field.
|
long |
getNumerator()
Public method to access the numerator field.
|
int |
hashCode()
Hashcode has to be equal for equal fractions.
|
long |
integerPart()
Integer part of the (improper) fraction.
|
Lfraction |
inverse()
Inverse of the fraction.
|
static void |
main(java.lang.String[] param)
Main method.
|
Lfraction |
minus(Lfraction m)
Difference of fractions.
|
Lfraction |
opposite()
Opposite of the fraction.
|
Lfraction |
plus(Lfraction m)
Sum of fractions.
|
Lfraction |
times(Lfraction m)
Multiplication of fractions.
|
double |
toDouble()
Approximate value of the fraction.
|
static Lfraction |
toLfraction(double f,
long d)
Double value f presented as a fraction with denominator d > 0.
|
java.lang.String |
toString()
Conversion to string.
|
static Lfraction |
valueOf(java.lang.String s)
Conversion from string to the fraction.
|
public Lfraction(long a, long b)
a
- numeratorb
- denominator > 0public static void main(java.lang.String[] param)
public long getNumerator()
public long getDenominator()
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object m)
equals
in class java.lang.Object
m
- second fractionpublic int hashCode()
hashCode
in class java.lang.Object
public Lfraction plus(Lfraction m)
m
- second addendpublic Lfraction times(Lfraction m)
m
- second factorpublic Lfraction inverse()
public Lfraction opposite()
public Lfraction minus(Lfraction m)
m
- subtrahendpublic Lfraction divideBy(Lfraction m)
m
- divisorpublic int compareTo(Lfraction m)
compareTo
in interface java.lang.Comparable<Lfraction>
m
- second fractionpublic java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
public long integerPart()
public Lfraction fractionPart()
public double toDouble()
public static Lfraction toLfraction(double f, long d)
f
- real numberd
- positive denominator for the resultpublic static Lfraction valueOf(java.lang.String s)
s
- string form (as produced by toString) of the fraction