|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.pacbell.jfai.toh.domain.Pin
public class Pin
A pin holds a stack of disks. It has a name, such as 'left'.
| Constructor Summary | |
|---|---|
Pin(String name)
Creates a named pin. |
|
| Method Summary | |
|---|---|
void |
add(Disk disk)
Insert the given disk into the tower at the appropriate position according to the disk size. |
void |
addTop(Disk disk)
Put the given disk on top of the existing tower. |
int |
diskLocation(Disk disk)
Answer the 1-based position of the given disk in the receiver's tower. |
Stack<Disk> |
getDisks()
Gets the disks. |
String |
getName()
Gets the name. |
int |
getNumberOfDisks()
Gets the total number of disks at this pin. |
boolean |
isAcceptable(Disk probe)
Answer if the argument can be placed on top of the existing tower. |
boolean |
remove(Disk disk)
If the specified disk is at this pin, then remove it and answer true, else answer false. |
Disk |
removeTop()
Remove the topmost disk from the tower and answer it. |
void |
setName(String name)
Sets the name. |
Disk |
top()
Answer the topmost disk. |
String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Pin(String name)
name - the name, such as 'left'| Method Detail |
|---|
public void add(Disk disk)
disk - the disk to be added
public void addTop(Disk disk)
throws InvalidMoveException
disk - The disk to be added
InvalidMoveException - if an invalid move is attemptedpublic int diskLocation(Disk disk)
disk - a disk
public Stack<Disk> getDisks()
public String getName()
public int getNumberOfDisks()
public boolean isAcceptable(Disk probe)
probe - A disk
public boolean remove(Disk disk)
disk - A disk
public Disk removeTop()
public void setName(String name)
name - the name of the pin, e.g. 'left'public Disk top()
public String toString()
toString in class ObjectObject.toString()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||