

PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 
java.lang.Object type.lib.Fraction type.lib.MixedNumber
public class MixedNumber
This class encapsulates a mixed number. A mixed number
created by this class has four attributes: a sign
s
, a whole part w
, a proper numerator
n
, and a proper denominator d
; where
s
is +1 or 1; w
, n
, d
are unsigned integers; and n
<d
(i.e. the fraction is proper).
The corresponding rational value of the mixed number is
s*(w+n/d)
or the fraction s*(wd+n)/d
.
The class derives all its features from its superclass, Fraction,
because any mixed number is a (possibly improper) fraction.
The case of zero denominator is handled the same as in Fraction
(see its API for details). In particular, if a string representation
of a zerodenominator mixed number is requested, the literal
NaMN
(Not a Mixed Number) is returned.
Field Summary 

Fields inherited from class type.lib.Fraction 

isQuoted, rng, separator 
Constructor Summary  

MixedNumber()
Construct a default mixed number with sign +1, whole part equal to 0, numerator equal to zero, and denominator equal to 1. 

MixedNumber(int s,
long w,
long n,
long d)
Construct a mixed number having the passed sign, whole part proper numerator, and proper denominator. 

MixedNumber(MixedNumber mixed)
Construct a copy of the passed mixed number. 
Method Summary  

long 
getProperDenominator()
An accessor to the proper denominator of this mixed number. 
long 
getProperNumerator()
An accessor to the proper numerator of this mixed number. 
static Fraction 
getRandom()
Create a random mixed number with a randomly selected sign and with a whole part, proper numerator, and denominator uniformly distributed in [0,1000) (but no zerodenominator mixed number is generated). 
int 
getSign()
Determine and return the sign of this mixed number. 
long 
getWhole()
An accessor to the whole part of this mixed number. 
boolean 
resembles(MixedNumber other)
Determine if this mixed number resembles
the passed one. 
java.lang.String 
toString()
Determine and return a string representation of this
mixed number. 
Methods inherited from class type.lib.Fraction 

add, cloneMe, compareTo, divide, equals, getDenominator, getNumerator, getSeparator, hashCode, multiply, pow, resembles, setDenominator, setFraction, setFraction, setNumerator, setSeed, setSeparator, subtract, toProperString 
Methods inherited from class java.lang.Object 

clone, finalize, getClass, notify, notifyAll, wait, wait, wait 
Constructor Detail 

public MixedNumber()
public MixedNumber(MixedNumber mixed)
mixed
 the mixed number to copy.public MixedNumber(int s, long w, long n, long d)
s
 the sign of the mixed number.
Must be +1 or 1.w
 the whole part of the mixed number.
Must be nonnegative.n
 the proper numerator of the mixed number to construct.
Must be nonnegative.d
 the proper denominator of the mixed number to construct.
Must be nonnegative.
java.lang.RuntimeException
 if any of the passed parameters is not valid as specified above.Method Detail 

public int getSign()
this
mixed number.
this
mixed number.
The return is +1 is the mixed number is positive or zero, and
1 if the mixed number is negative.public long getWhole()
this
mixed number.
this
mixed number.
The return is always nonnegative.public long getProperNumerator()
this
mixed number.
this
mixed number.
The return is always nonnegative.public long getProperDenominator()
this
mixed number.
this
mixed number.
The return is always nonnegative.public java.lang.String toString()
this
mixed number.
toString
in class Fraction
this
mixed number, followed by a space, followed
by its whole part, followed by a space, followed by the
proper numerator and poper denominator separated by a slash.
Note however that if the proper denominator is zero, the literal
NaMN
is returned.public boolean resembles(MixedNumber other)
this
mixed number resembles
the passed one. Two mixed numbers are said to resemble
each other if they have the same whole part.
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 Fraction getRandom()
MixedNumber
instance 50% of the
times. In the remaining 50%, the return is
supplied by the getRandom
method of
the Fraction
superclass.
This method was added for pedagogical reasons.


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