: Class Pile

Class Pile

java.lang.Object
  |
  +--Pile

public class Pile
extends java.lang.Object


Constructor Summary
Pile()
          Creates a new empty pile.
 
Method Summary
 void addDisk(Disk disk)
          adds a new disk onto the top of the pile.
 int getNumberOfDisks()
          returns the number of disks on the pile.
 boolean isEmpty()
          returns true if the pile is empty, false otherwise.
 Disk removeDisk()
          removes the first disk on the pile if exists and returns it.
 Disk topDisk()
          returns the top disk on the pile without removing it from the pile.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Pile

public Pile()
Creates a new empty pile.
Method Detail

getNumberOfDisks

public final int getNumberOfDisks()
returns the number of disks on the pile.
Returns:
the number of disks on the pile.

removeDisk

public Disk removeDisk()
removes the first disk on the pile if exists and returns it.
Returns:
the first disk on the pile, if exists.

addDisk

public void addDisk(Disk disk)
adds a new disk onto the top of the pile.
Parameters:
disk - the disk to be added onto the top of the pile.

topDisk

public Disk topDisk()
returns the top disk on the pile without removing it from the pile.
Returns:
the top disk on the pile.

isEmpty

public boolean isEmpty()
returns true if the pile is empty, false otherwise.
Returns:
true if the pile is empty, false otherwise.