|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectAnswer
public class Answer
This class presents fractions of form n/d where n and d are integer numbers. Basic operations and arithmetics for fractions are provided.
Constructor Summary | |
---|---|
Answer(int a,
int b)
Constructor. |
Method Summary | |
---|---|
java.lang.Object |
clone()
Clone of the fraction. |
int |
compareTo(Answer m)
Comparision of fractions. |
Answer |
divideBy(Answer m)
Quotient of fractions. |
boolean |
equals(java.lang.Object m)
Equality test. |
Answer |
fractionPart()
Extract fraction part of the (improper) fraction (a proper fraction without the integer part). |
int |
getDenominator()
Public method to access the denominator field. |
int |
getNumerator()
Public method to access the numerator field. |
int |
integerPart()
Integer part of the (improper) fraction. |
Answer |
inverse()
Inverse of the fraction. n/d becomes d/n. |
Answer |
minus(Answer m)
Difference of fractions. |
Answer |
opposite()
Opposite of the fraction. n/d becomes -n/d. |
Answer |
plus(Answer m)
Sum of fractions. |
Answer |
times(Answer m)
Multiplication of fractions. |
static Answer |
toAnswer(double f,
int d)
Double value f presented as a fraction with denominator d > 0. |
double |
toDouble()
Approximate value of the fraction. |
java.lang.String |
toString()
Conversion to string. |
static Answer |
valueOf(java.lang.String s)
Conversion from string to the fraction. |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Answer(int a, int b)
a
- numeratorb
- denominator > 0Method Detail |
---|
public int getNumerator()
public int 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 fraction
public Answer plus(Answer m)
m
- second addend
public Answer times(Answer m)
m
- second factor
public Answer inverse()
public Answer opposite()
public Answer minus(Answer m)
m
- subtrahend
public Answer divideBy(Answer m)
m
- divisor
public int compareTo(Answer m)
compareTo
in interface java.lang.Comparable<Answer>
m
- second fraction
public java.lang.Object clone()
clone
in class java.lang.Object
public int integerPart()
public Answer fractionPart()
public double toDouble()
public static Answer toAnswer(double f, int d)
f
- real numberd
- positive denominator for the result
public static Answer valueOf(java.lang.String s)
s
- string form (as produced by toString) of the fraction
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |