|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--MyInteger
Encapsulates a mutable int
. A MyInteger
object stores a single integer value, and that integer value may
change during the lifetime of the object.
Constructor Summary | |
MyInteger(int i)
Constructs a new MyInteger object that initially stores
the integer value i . |
Method Summary | |
java.lang.Object |
clone()
Returns a new MyNumber object that initially
equals this . |
MyNumber |
createCompatible(int i)
Returns a new MyNumber object that initially holds
the value i . |
boolean |
divides(MyIntegralNumber n)
Returns true if n is evenly divisible by this . |
boolean |
equals(java.lang.Object o)
Tests whether o and this are equal. |
boolean |
lessThan(MyNumber n)
Returns true if this is smaller than
n . |
void |
minus()
Replaces this with -this . |
void |
plus(MyNumber n)
Replaces this with this + n . |
MyNumber |
squareOf()
Returns a new object holding the square of the value of this . |
void |
times(MyNumber n)
Replaces this with this * n . |
java.lang.String |
toString()
Retrieves the decimal representation of the stored integer. |
Methods inherited from class java.lang.Object |
|
Constructor Detail |
public MyInteger(int i)
MyInteger
object that initially stores
the integer value i
.i
- the integer value to initially store in the new objectMethod Detail |
public java.lang.Object clone()
MyNumber
object that initially
equals this
.
[The returned object is guaranteed to be an instance of
this
's class.]
MyNumber
(of the same class as
this
) that takes this
's
integer value as its initial stored valuepublic MyNumber createCompatible(int i)
MyNumber
object that initially holds
the value i
.
[The returned object is guaranteed to be an instance of
this
's class.]
Example:
// construct n... MyNumber n = new MyInteger(3); // increment n... MyNumber one = n.createCompatible(1); // ...one is a MyInteger. n.plus(one);[The behavior of the
createCompatible
method is
undefined if i
is too large (or too small) to be
handled by this
's variety of number.]MyNumber
(of the same class as
this
) that takes i
as its
initial stored valuepublic boolean lessThan(MyNumber n)
true
if this
is smaller than
n
.
[The behavior of the lessThan
method is undefined if
n
is not compatible with this
.]
n
- the number to compare against this
true
if this
is less than
n
; false
otherwisepublic boolean equals(java.lang.Object o)
o
and this
are equal.o
- the object to compare against this
true
if (1) o
is a MyNumber
that is compatible with this
and (2) o
and this
currently store the same integer value;
false
otherwisepublic void minus()
this
with -this
.public void plus(MyNumber n)
this
with this + n
.
[The behavior of the plus
method is undefined if
n
is not compatible with this
.]
n
- the number to be added to this
public MyNumber squareOf()
this
.
[The returned object is guaranteed to be an instance of
this
's class.]
MyNumber
object (of the same class
as this
) that initially stores the
square of this object's integer value.public void times(MyNumber n)
this
with this * n
.
[The behavior of the times
method is undefined if
n
is not compatible with this
.]
n
- the number by which this
is to be scaledpublic boolean divides(MyIntegralNumber n)
true
if n
is evenly divisible by this
.
[The divides
method's behavior is undefined when this
is zero.]
n
- the integral number to divide intotrue
if n
is divisible by
this
; false
otherwisepublic java.lang.String toString()
String
that represents the stored integer,
in decimal
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |