Class Pile

java.lang.Object
  extended by Pile

public class Pile
extends java.lang.Object

Pile of sticks for the nim game.


Constructor Summary
Pile()
          Create an empty Pile.
Pile(int number)
          Create a Pile with the specified number of sticks.
 
Method Summary
 void remove(int number)
          Remove the specified number of sticks from this Pile.
 void setSize(int number)
          Set the number of sticks in this Pile.
 int size()
          Number of sticks in this Pile.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Pile

public Pile()
Create an empty Pile.

Postcondition: this.size() == 0


Pile

public Pile(int number)
Create a Pile with the specified number of sticks.

Precondition: number >= 0

Postcondition: this.size() == number

Parameters:
number - Initial number of sticks in the pile.
Method Detail

size

public int size()
Number of sticks in this Pile.

Postcondition: this.size() >= 0

Returns:
The current number of sticks in the pile.

setSize

public void setSize(int number)
Set the number of sticks in this Pile.

Precondition: number >= 0

Postcondition: this.size() == number

Parameters:
number - The desired number of sticks in the pile.

remove

public void remove(int number)
Remove the specified number of sticks from this Pile. If the specified number is more than the Pile size, remove all the sticks.

Precondition: number >= 0

Postcondition: this.size == max(0, old.size - number)

Parameters:
number - The number of sticks to remove from the pile.