Class FractClass

java.lang.Object
   |
   +----FractClass

public class FractClass
extends Object
FractClass implements a Fraction ADT.
Integrity Constraint: The object's value is the
correct value of the last fraction Stored or computed.

Version:
1.2, 1/99
Author:
Jeff Offutt

Constructor Index

 o FractClass()
Constructor : Sets fraction to 0/1
pre: null
post: fraction's value is 0/1; number of fractions is incremented
 o FractClass(int, int)
Constructor : Initialize a new fraction with supplied values
pre: Den is not 0
post: fraction's value is Num/Den; number of fractions is incremented

Method Index

 o Add(FractClass)
Mutator : Adds two fractions, F1 = F1+F2
pre: Both denominators must be the same
(checked with the exception ArithmeticException)
post: Object's value is old-value+Right
 o equals(Object)
Accessor : Compares two fractions for equality
pre: null
post: null
 o GetNumFracs()
Class Method : Returns the current number of fractions
pre: null
post: null
 o main(String[])
Main program function, tests the ADT class
 o Mult(FractClass)
Mutator : Multiplies two fractions, F1 = F1*F2
pre: null
post: Object's value is old-value*Right
 o PrintFrac()
Accessor : Prints a fraction using println
pre: null
post: Fraction is printed
 o toString()
Accessor : Converts a fraction to a string for println
pre: null
post: null

Constructors

 o FractClass
 public FractClass()
Constructor : Sets fraction to 0/1
pre: null
post: fraction's value is 0/1; number of fractions is incremented

Returns:
None
 o FractClass
 public FractClass(int Num,
                   int Den)
Constructor : Initialize a new fraction with supplied values
pre: Den is not 0
post: fraction's value is Num/Den; number of fractions is incremented

Parameters:
Num - Integer numerator
Den - Integer denominator
Returns:
None

Methods

 o GetNumFracs
 public static int GetNumFracs()
Class Method : Returns the current number of fractions
pre: null
post: null

Returns:
An integer, the current number of fractions
 o Add
 public void Add(FractClass Right)
Mutator : Adds two fractions, F1 = F1+F2
pre: Both denominators must be the same
(checked with the exception ArithmeticException)
post: Object's value is old-value+Right

Parameters:
Right - FractClass right-hand-side
Returns:
None
 o Mult
 public void Mult(FractClass Right)
Mutator : Multiplies two fractions, F1 = F1*F2
pre: null
post: Object's value is old-value*Right

Parameters:
Right - FractClass right-hand-side
Returns:
None
 o equals
 public boolean equals(Object Right)
Accessor : Compares two fractions for equality
pre: null
post: null

Parameters:
Right - FractClass right-hand-side
Returns:
boolean (F1 == F2)
Overrides:
equals in class Object
 o PrintFrac
 public void PrintFrac()
Accessor : Prints a fraction using println
pre: null
post: Fraction is printed

Returns:
None
 o toString
 public String toString()
Accessor : Converts a fraction to a string for println
pre: null
post: null

Returns:
String representation of the value is returned
Overrides:
toString in class Object
 o main
 public static void main(String argv[])
Main program function, tests the ADT class

Returns:
None