|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmyutil.Fraction
public class Fraction
An instance of this class represents a fraction.
Field Summary | |
---|---|
private int |
denominator
the denominator of this fraction |
private int |
numerator
the numerator of this fraction |
Constructor Summary | |
---|---|
Fraction()
Creates a fraction 0/1 |
|
Fraction(Fraction frac)
Creates a copy of frac |
|
Fraction(int number)
Creates a fraction number/1 |
|
Fraction(int num,
int denom)
Creates a fraction num/denom. |
Method Summary | |
---|---|
Fraction |
add(Fraction frac)
Returns the sum of this Fraction and the parameter frac. |
Fraction |
add(int number)
Returns the sum of this Fraction and the int parameter number. |
private double |
decimal()
Returns the decimal equivalent of this fraction |
Fraction |
divide(Fraction frac)
Returns the quotient of this Fraction divided by the parameter frac. |
Fraction |
divide(int number)
Returns the quotient of this Fraction divided by the int parameter number. |
boolean |
equals(Fraction frac)
Compares this fraction and the parameter frac for equality. |
static int |
gcd(int m,
int n)
Returns the greatest common divisor of the parameters m and n |
int |
getDenominator()
Returns the denominator of this fraction |
int |
getNumerator()
Returns the numerator of this fraction |
static Fraction |
min(Fraction f1,
Fraction f2)
Returns the smaller of the two parameters f1 and f2 |
Fraction |
multiply(Fraction frac)
Returns the product of this Fraction and the parameter frac. |
Fraction |
multiply(int number)
Returns the product of this Fraction and the int parameter number. |
void |
setDenominator(int denom)
Sets the denominator of this fraction |
void |
setNumerator(int num)
Sets the numerator of this fraction |
Fraction |
simplify()
Returns a new Fraction object that is in the simplest form of this Fraction object. |
Fraction |
subtract(Fraction frac)
Returns the difference of this Fraction and the parameter frac. |
Fraction |
subtract(int number)
Returns the difference of this Fraction and the int parameter number. |
java.lang.String |
toString()
Returns the String representation of this Fraction |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private int numerator
private int denominator
Constructor Detail |
---|
public Fraction()
public Fraction(int number)
number
- the numeratorpublic Fraction(Fraction frac)
frac
- a copy of this parameter is createdpublic Fraction(int num, int denom)
num
- the numeratordenom
- the denominatorMethod Detail |
---|
public static int gcd(int m, int n)
m
- the first numbern
- the second number
public static Fraction min(Fraction f1, Fraction f2)
f1
- the first fraction to comparef2
- the second fraction to compare
public Fraction add(Fraction frac)
frac
- the Fraction to add to this
Fraction
public Fraction add(int number)
number
- the integer to add to this
Fraction
public Fraction divide(Fraction frac)
frac
- the divisor of the division
public Fraction divide(int number)
number
- the divisor
public boolean equals(Fraction frac)
frac
- the fraction object to compare
public int getDenominator()
public int getNumerator()
public Fraction multiply(Fraction frac)
frac
- the multiplier of the multiplication
public Fraction multiply(int number)
number
- the muliplier
public void setDenominator(int denom)
denom
- the denominator of this fractionpublic void setNumerator(int num)
num
- the numerator of this fractionpublic Fraction simplify()
public Fraction subtract(Fraction frac)
frac
- the Fraction to subtract from
this Fraction
public Fraction subtract(int number)
number
- the int value to subtract
public java.lang.String toString()
toString
in class java.lang.Object
private double decimal()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |