public class Fraction
extends java.lang.Object
doubles.| Constructor and Description |
|---|
Fraction(int numerator,
int denominator)
Create a new
Fraction, from its numerator and
denominator. |
| Modifier and Type | Method and Description |
|---|---|
Fraction |
add(Fraction other)
Add a second
Fraction to this. |
Fraction |
divide(Fraction other)
Divide
this by a second Fraction. |
boolean |
equals(Fraction other)
Build a
true if this is equivalent to other; otherwise false. |
int |
getDenominator()
Accessor for the denominator.
|
int |
getNumerator()
Accessor for the numerator.
|
Fraction |
multiply(Fraction other)
Multiply a second
Fraction by this. |
void |
setDenominator(int newDenominator)
Mutator for the denominator.
|
void |
setNumerator(int newNumerator)
Mutator for the numerator.
|
Fraction |
subtract(Fraction other)
Subtract a second
Fraction from this. |
double |
toDouble()
Calculate the
double whose value best approximates
this's value. |
java.lang.String |
toString()
Build a
String representing this
Fraction, as (numerator/denominator). |
public Fraction(int numerator,
int denominator)
Fraction, from its numerator and
denominator.public Fraction add(Fraction other)
Fraction to this.other - the other Fraction to addFractionpublic Fraction subtract(Fraction other)
Fraction from this.other - the other Fraction to subtractFractionpublic Fraction multiply(Fraction other)
Fraction by this.other - the other Fraction to multiplyFractionpublic Fraction divide(Fraction other)
this by a second Fraction.other - the other Fraction by which to divideFractionpublic double toDouble()
double whose value best approximates
this's value.public java.lang.String toString()
String representing this
Fraction, as (numerator/denominator).toString in class java.lang.Object(numerator/denominator)public boolean equals(Fraction other)
true if this is equivalent to other; otherwise false.other - the other Fractionpublic int getNumerator()
public int getDenominator()
public void setNumerator(int newNumerator)
newNumerator - the new numeratorpublic void setDenominator(int newDenominator)
newDenominator - the new denominator