|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--RussianDoll
We designed this class in lecture. A Russian doll is an object that contains another Russian doll. There is a special Russian doll called ZERO that contains itself. Our public methods do not allow the user to construct any other dolls that are nested inside themselves.
Russian dolls can be used to represent integers without actually using Java's integer class. ZERO represents 0, a doll that contains ZERO represents 1, a doll that contains 1 represents 2, etc.
Notice that there may be many different dolls that represent a number such as 5. In other words, even if rd1 and rd2 are both dolls that represent 5, there is no guarantee that rd1 == rd2. They might be different objects in memory.
Field Summary | |
private RussianDoll |
inner
Contains the next doll in, or in the special case of ZERO, contains this doll itself. |
static RussianDoll |
ZERO
The special doll representing ZERO. |
Constructor Summary | |
private |
RussianDoll()
A special constructor returning a cyclic doll. |
private |
RussianDoll(RussianDoll rd)
The usual constructor. |
Method Summary | |
RussianDoll |
add(RussianDoll val)
Implements Numeric.add(Numeric) . |
RussianDoll |
bigger()
Adds one. |
static void |
main(java.lang.String[] args)
A test method of your choice; do whatever you want here. |
RussianDoll |
smaller()
Subtracts one. |
java.lang.String |
toString()
Converts to a string representing a Peano integer: "0", "S0", "SS0", etc. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final RussianDoll ZERO
private RussianDoll inner
Constructor Detail |
private RussianDoll(RussianDoll rd)
private RussianDoll()
Method Detail |
public RussianDoll smaller()
public RussianDoll bigger()
public java.lang.String toString()
toString
in class java.lang.Object
public RussianDoll add(RussianDoll val)
Numeric.add(Numeric)
.
public static void main(java.lang.String[] args)
NumericTest
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |