com.generationjava.math
Class Fraction

java.lang.Object
  extended bycom.generationjava.math.Fraction

public class Fraction
extends Object

A Fraction, containing a denominator and a numerator.


Constructor Summary
Fraction(int num)
          Create a Fraction that represents the number specified..
Fraction(int num, int den)
          Create a fraction.
 
Method Summary
 Fraction add(Fraction f)
          Add a Fraction to this Fraction.
 Fraction div(Fraction f)
          Divide this fraction by another.
 boolean equals(Object obj)
          Are two fractions equal?
static int gcd(int i1, int i2)
          Find the greatest common divisor of two numbers.
 int hashCode()
           
 Fraction inverse()
          Invert this fraction.
 Fraction mul(Fraction f)
          Multiple this fraction by another..
static Fraction reduce(Fraction f)
          Reduce a fraction down to its lowest level.
 Fraction sub(Fraction f)
          Subtract a Fraction from this Fraction.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Fraction

public Fraction(int num,
                int den)
Create a fraction. num/den

Parameters:
num - int numerator - one on top
den - int denominator - one on bottom

Fraction

public Fraction(int num)
Create a Fraction that represents the number specified..

Parameters:
num - int numerator
Method Detail

gcd

public static int gcd(int i1,
                      int i2)
Find the greatest common divisor of two numbers.


reduce

public static Fraction reduce(Fraction f)
Reduce a fraction down to its lowest level.


add

public Fraction add(Fraction f)
Add a Fraction to this Fraction.


sub

public Fraction sub(Fraction f)
Subtract a Fraction from this Fraction.


mul

public Fraction mul(Fraction f)
Multiple this fraction by another..


div

public Fraction div(Fraction f)
Divide this fraction by another.


inverse

public Fraction inverse()
Invert this fraction.


equals

public boolean equals(Object obj)
Are two fractions equal?


hashCode

public int hashCode()

toString

public String toString()


Copyright © 2000-2005 OSJava. All Rights Reserved.