public class Fraction extends Object
Constructor and Description |
---|
Fraction()
Initializes the numerator of this fraction to 0 and the denominator
of this faction to 1.
|
Fraction(long numerator,
long denominator)
Initializes this fraction with the passed numerator and denominator.
|
Modifier and Type | Method and Description |
---|---|
void |
add(Fraction other)
Adds the passed fraction to this fraction.
|
static Fraction |
createFraction()
Returns a random fraction.
|
void |
divide(Fraction other)
Divides the passed fraction to this fraction.
|
boolean |
equals(Object object)
Tests if this fraction is the same as the passed one.
|
long |
getDenominator()
Returns the denominator of this fraction.
|
long |
getNumerator()
Returns the numerator of this fraction.
|
int |
hashCode()
Returns a hash code for this fraction.
|
void |
multiply(Fraction other)
Multiplies the passed fraction to this fraction.
|
void |
setDenominator(long denominator)
Sets the denominator of this fraction to the passed denominator.
|
void |
setNumerator(long numerator)
Sets the numerator of this fraction to the passed numerator.
|
void |
subtract(Fraction other)
Subtracts the passed fraction to this fraction.
|
String |
toString()
Returns a string representation of this fraction.
|
public Fraction()
public Fraction(long numerator, long denominator)
numerator
- the numerator of this fraction.denominator
- the denominator of this fraction.public static Fraction createFraction()
public void add(Fraction other)
other
- the fraction to add to this fraction.public void subtract(Fraction other)
other
- the fraction to subtract to this fraction.public void multiply(Fraction other)
other
- the fraction to multiply to this fraction.public void divide(Fraction other)
other
- the fraction to divide to this fraction.public void setNumerator(long numerator)
numerator
- the new numerator.public long getNumerator()
NumberFormatException
- if the numerator of this fraction is not a long.public void setDenominator(long denominator)
denominator
- the new denominator.public long getDenominator()
NumberFormatException
- if the denominator of this fraction is not a long.public String toString()
public boolean equals(Object object)