mae.tut.num
Class Number

java.lang.Object
  extended bymae.tut.num.Number
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
Complex, Matrix, Ordinal

public abstract class Number
extends java.lang.Object
implements java.io.Serializable

The abstract superclass of all numbers: Whole, Rational, Decimal, Complex, Matrix.

Subclasses of Number must provide methods to add, multiply by another Number, find the multiplicative inverse, and give the float value.

Number objects are immutable: constructed once, never modified.

 V1.0 Jan 12, 2002 Mutable objects
 V1.1 Jan 26, 2002 exp() generalized
 V2.0 Jun 30, 2003 NetBeans implementation: immutable
 V2.1 Dec 30, 2003 Factory class redesigned -> Cruncher
 

See Also:
Serialized Form

Method Summary
abstract  Number add(Number n)
          Adds this Number to another Number n and returns the result.
 int hashCode()
          hashCode that would be returned by a Float object with the same value.
abstract  Number inverse()
          Returns the multiplicative inverse of this Number.
abstract  Number mult(Number n)
          Multiplies this Number by another Number n and returns the result.
abstract  float value()
          Returns the float value of this Number.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

add

public abstract Number add(Number n)
Adds this Number to another Number n and returns the result.

If this Number and n are of the same type, returned result must be of that type.
If this and n are of different types, returned result must be as narrow as possible.
But in all cases add(n) and n.add(this) must return the same Number.


mult

public abstract Number mult(Number n)
Multiplies this Number by another Number n and returns the result.

If this Number and n are of the same type, returned result must be of that type.
If this and n are of different types, returned result must be as narrow as possible.
But in all cases mult(n) and n.mult(this) must return the same Number.


inverse

public abstract Number inverse()
Returns the multiplicative inverse of this Number.

For any Number n, if inverse() is defined, n.inverse().inverse() must be equal to n.
Also n.inverse().mult(n).value() must be 1.0


value

public abstract float value()
Returns the float value of this Number.


hashCode

public int hashCode()
hashCode that would be returned by a Float object with the same value.

Equal Numbers have the same value, thus the same hashCode.

Needed by subclasses that redefine equals(Object)

See Also:
Ordinal.equals(Object), Complex.equals(Object)