java.lang.ObjectFraction
public class Fraction
Maintains a fraction of the form n/d where n and d are integers.
| Field Summary | |
|---|---|
private int |
den
The denominator of the fraction. |
private int |
num
The numerator of the fraction. |
| Constructor Summary | |
|---|---|
Fraction()
Default constructor: set fraction to 0/1. |
|
Fraction(int n)
One parameter constructor: set fraction to n/1. |
|
Fraction(int n,
int d)
Two parameter constructor: set fraction to n/d. |
|
| Method Summary | |
|---|---|
Fraction |
addFraction(Fraction f)
Fraction adder. |
private int |
gcd(int i,
int j)
Greatest common devisor of i and j. |
int |
getDen()
Denominator reader. |
int |
getNum()
Numerator reader. |
double |
getValue()
Get the (double) value of the fraction. |
private void |
reduce()
Reduct the fraction to canonical form. |
void |
setFraction(int n,
int d)
Fraction writer: set fraction to n/d. |
java.lang.String |
toString()
Return a pretty String version of the fraction. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
private int num
private int den
| Constructor Detail |
|---|
Fraction()
Fraction(int n)
n - the numerator of the fraction.
Fraction(int n,
int d)
n - the numerator of the fraction.d - the denominator of the fraction.| Method Detail |
|---|
private int gcd(int i,
int j)
i - An integerj - Another integer
private void reduce()
public void setFraction(int n,
int d)
public int getNum()
public int getDen()
public double getValue()
public java.lang.String toString()
toString in class java.lang.Objectpublic Fraction addFraction(Fraction f)