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
-
FractClass()
-
Constructor : Sets fraction to 0/1
pre: null
post: fraction's value is 0/1; number of fractions is incremented
-
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
-
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
-
equals(Object)
-
Accessor : Compares two fractions for equality
pre: null
post: null
-
GetNumFracs()
-
Class Method : Returns the current number of fractions
pre: null
post: null
-
main(String[])
-
Main program function, tests the ADT class
-
Mult(FractClass)
-
Mutator : Multiplies two fractions, F1 = F1*F2
pre: null
post: Object's value is old-value*Right
-
PrintFrac()
-
Accessor : Prints a fraction using println
pre: null
post: Fraction is printed
-
toString()
-
Accessor : Converts a fraction to a string for println
pre: null
post: null
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
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
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
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
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
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
PrintFrac
public void PrintFrac()
- Accessor : Prints a fraction using println
pre: null
post: Fraction is printed
- Returns:
- None
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
main
public static void main(String argv[])
- Main program function, tests the ADT class
- Returns:
- None