|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.ObjectFraction
public class Fraction
A class to represent fractions. Fractions will always be in reduced form.
| Constructor Summary | |
|---|---|
Fraction()
Default constructor - sets the numerator to 0 and the denominator to 1. |
|
Fraction(int numerator)
Constructor - Constructs a fraction with the specified numerator and a denominator of 1. |
|
Fraction(int numerator,
int denominator)
Constructor - Constructs a fraction with the specified numerator and denominator (the fraction will be reduced, if possible). |
|
| Method Summary | |
|---|---|
Fraction |
add(Fraction other)
Command method that adds this fraction to the other fraction and returns the result as a third new fraction. |
Fraction |
div(Fraction other)
Command method that divides this fraction by the other fraction and returns the result as a third new fraction. |
boolean |
equals(Fraction other)
Query method to determine if one fraction is equal to another. |
int |
getDenominator()
Query method to get the denominator of the fraction |
int |
getNumerator()
Query method to get the numerator of the fraction |
Fraction |
mul(Fraction other)
Command method that multiplies this fraction to the other fraction and returns the result as a third new fraction. |
Fraction |
sub(Fraction other)
Command method that subracts the other fraction from this fraction and returns the result as a third new fraction. |
java.lang.String |
toString()
Query method to obtain a string-representation of the fraction. |
double |
value()
Query/Command method to get the value of the fraction as a number. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Fraction()
public Fraction(int numerator)
numerator - The numerator of the fraction.
public Fraction(int numerator,
int denominator)
numerator - The numerator of the fraction.denominator - The denominator of the fraction.| Method Detail |
|---|
public int getNumerator()
public int getDenominator()
public double value()
public java.lang.String toString()
toString in class java.lang.Objectpublic boolean equals(Fraction other)
other - The fraction to compare to this fraction.
public Fraction add(Fraction other)
other - The fraction to add to this fraction.
public Fraction sub(Fraction other)
other - The fraction to subtract from this fraction.
public Fraction mul(Fraction other)
other - The fraction to multiply with this fraction.
public Fraction div(Fraction other)
other - The fraction to divide this fraction by.
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||