

PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 
java.lang.Object type.lib.FractionNS
public class FractionNS
This class is identical to the Fraction
class
except for three nonstandard (NS) features. For
pedagogical reasons, neither toString
nor equals
nor hashCode
is present.
Field Summary  

static boolean 
isQuoted
A flag that determines if the return of the toProperString()
method is surrounded by quotes or not. 
protected static java.util.Random 
rng
The random number generator used by the getRandom() method. 
char 
separator
A character that separates the numerator denominator pair in the return of the Object.toString() method. 
Constructor Summary  

FractionNS()
Construct a default fraction with numerator equal to 0, denominator equal to 1, and separator equal to '/'. 

FractionNS(FractionNS fraction)
Construct a copy of the passed Fraction. 

FractionNS(long numerator,
long denominator)
Construct a fraction with the passed numerator and denominator and a '/' separator. 

FractionNS(long numerator,
long denominator,
char separator)
Construct a fraction with the passed numerator, denominator, and separator. 
Method Summary  

void 
add(FractionNS other)
Add the passed fraction to the fraction on which it was called. 
FractionNS 
cloneMe()
Copy the state of this object. 
int 
compareTo(FractionNS other)
Compare this object with the specified object for order. 
void 
divide(FractionNS other)
Divide the fraction on which the method was called by the passed fraction. 
long 
getDenominator()
An accessor to the denominator of this fraction. 
long 
getNumerator()
An accessor to the numerator of this fraction. 
static FractionNS 
getRandom()
Create a random fraction. 
char 
getSeparator()
An accessor to the separator of this fraction. 
void 
multiply(FractionNS other)
Multiply the fraction on which the method was called by the passed fraction. 
void 
pow(int exponent)
Raise the fraction on which the method was called to the passed exponent. 
boolean 
resembles(FractionNS other)
Determine if this fraction resembles
the passed one. 
void 
setDenominator(long denominator)
A mutator for the denominator of this fraction. 
void 
setFraction(FractionNS other)
A mutator for this fraction. 
void 
setFraction(long numerator,
long denominator)
A mutator for this fraction. 
void 
setNumerator(long numerator)
A mutator of the numerator of this fraction. 
static void 
setSeed(long seed)
Change the seed of the random sequence returned by getRandom() . 
boolean 
setSeparator(char newSeparator)
A mutator of the separator of this fraction. 
void 
subtract(FractionNS other)
Subtract the passed fraction from the fraction on which it was called. 
java.lang.String 
toProperString()
Return this fraction as a proper fraction. 
Methods inherited from class java.lang.Object 

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait 
Field Detail 

public char separator
Object.toString()
method. The default
value is '/'
.
(Bad designshould have been kept private. Access would have still been possible via the existing public accessor and mutator.)
public static boolean isQuoted
toProperString()
method is surrounded by quotes or not. The
default value is true
.
(Bad designshould have been kept private. Access would
have still been possible via a public accessor, e.g. isQuoted
and a public mutator, e.g. setQuoted
.)
protected static java.util.Random rng
getRandom()
method.
Constructor Detail 

public FractionNS()
public FractionNS(long numerator, long denominator)
numerator
 the numerator of the fraction to construct.denominator
 the denominator of the fraction to construct.public FractionNS(FractionNS fraction)
fraction
 the Fraction to copy.public FractionNS(long numerator, long denominator, char separator)
numerator
 the numerator of the fraction to construct.denominator
 the denominator of the fraction to construct.separator
 the separator of the fraction to construct.Method Detail 

public void add(FractionNS other)
other
 the fraction to add to this
fraction.public void subtract(FractionNS other)
other
 the fraction to subtract from this
fraction.public void multiply(FractionNS other)
other
 the fraction to multiply this
fraction bypublic void divide(FractionNS other)
other
 the fraction to divide this
fraction bypublic void pow(int exponent)
exponent
 the exponent to raise this
fraction to (must be nonnegative).
java.lang.RuntimeException
 if the exponent is negative.public void setNumerator(long numerator)
this
fraction.
numerator
 the new numerator.public long getNumerator()
this
fraction.
this
fraction.public void setDenominator(long denominator)
this
fraction.
denominator
 the new denominator.public long getDenominator()
this
fraction.
this
fraction.public void setFraction(long numerator, long denominator)
this
fraction.
numerator
 the new numerator of the fraction.denominator
 the new denominator of the fraction.public void setFraction(FractionNS other)
this
fraction.
other
 the fraction whose numerator and denominator
will become those of this
fraction.public boolean setSeparator(char newSeparator)
this
fraction.
The separator must not be a letter or a digit.
newSeparator
 the new separator.
true
if the change was made (i.e. if
the passed parameter is neither a letter nor a digit), and
return false
otherwise.public char getSeparator()
this
fraction.
this
fraction.public java.lang.String toProperString()
this
fraction as a proper fraction.
Note that the literal "NaF" (Not A Fraction) is returned
if the denominator is zero to indicate that this is not
a valid fraction.
this
fraction in the form: w n/d
w
is a whole number and n
< d
.
The return is surrounded by double quotes if isQuoted
is true
.public boolean resembles(FractionNS other)
this
fraction resembles
the passed one. Two fractions are said to resemble
each other if they have a common denominator.
other
 a reference to the object to test resemblance with.
true
if other
is not null
and does resemble this
object.
The return is false
otherwise.public static FractionNS getRandom()
This method was added for pedagogical reasons.
public static void setSeed(long seed)
getRandom()
. This method
is meant to be used by a test harness so
that the same sequence can be generated
for the app being tested and its
oracle.
seed
 the initial seed for random
number generator.public FractionNS cloneMe()
this
object.
Fraction
object
having exactly the same state as this
one.public int compareTo(FractionNS other)
compareTo
in interface java.lang.Comparable<FractionNS>
other
 the Object to compare to.


PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 