jeops.examples.hanoi
Class Hanoi

java.lang.Object
  |
  +--jeops.examples.hanoi.Hanoi

public class Hanoi
extends java.lang.Object

This class models an encapsulation for a solution for the Towers of Hanoi problem.

Version:
0.01 15 Mar 1998
Author:
Carlos Figueira Filho (csff@di.ufpe.br)

Constructor Summary
Hanoi(int numDiscs, int source, int destination)
          Class constructor.
 
Method Summary
 void addMove(int from, int to)
          Adds a movement to the solution.
 void dump()
          Prints the tree for the expression of this precondition.
 void dump(int spaces)
          Prints the tree for the expression of this precondition.
 int getDestination()
          Returns the destination pin for this problem.
 int getDiscs()
          Returns the number of discs of this problem.
 int getIntermediate()
          Returns the intermediate pin form this problem.
 boolean getOk()
          Returns the state of this problem.
 int getSource()
          Returns the source pin for this problem.
 Hanoi getSub1()
          Returns the first subproblem for this problem.
 Hanoi getSub2()
          Returns the second subproblem for this problem.
 void setOk(boolean newValue)
          Determines whether this problem has already been solved.
 void setSub1(Hanoi sub1)
          Determines the first subproblem for this problem.
 void setSub2(Hanoi sub2)
          Determines the second subproblem for this problem.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Hanoi

public Hanoi(int numDiscs,
             int source,
             int destination)
Class constructor.
Parameters:
numDiscs - the number of the discs for this instance.
source - the source pin
destination - the destination pin
Method Detail

addMove

public void addMove(int from,
                    int to)
Adds a movement to the solution.
Parameters:
from - the pin from where the disc is moved.
to - the pin to where the disc is moved.

dump

public void dump()
Prints the tree for the expression of this precondition. Useful for debugging.

dump

public void dump(int spaces)
Prints the tree for the expression of this precondition. Useful for debugging.
Parameters:
spaces - the identation for the printed output.

getDestination

public int getDestination()
Returns the destination pin for this problem.
Returns:
the destination pin for this problem.

getDiscs

public int getDiscs()
Returns the number of discs of this problem.
Returns:
the number of discs of this problem.

getIntermediate

public int getIntermediate()
Returns the intermediate pin form this problem.
Returns:
the intermediate pin form this problem.

getOk

public boolean getOk()
Returns the state of this problem.
Returns:
true if this problem has already been solved; false otherwise.

getSource

public int getSource()
Returns the source pin for this problem.
Returns:
the source pin for this problem.

getSub1

public Hanoi getSub1()
Returns the first subproblem for this problem.
Returns:
the first subproblem for this problem.

getSub2

public Hanoi getSub2()
Returns the second subproblem for this problem.
Returns:
the second subproblem for this problem.

setOk

public void setOk(boolean newValue)
Determines whether this problem has already been solved.
Parameters:
newValue - the new value for the state of this problem.

setSub1

public void setSub1(Hanoi sub1)
Determines the first subproblem for this problem.
Parameters:
sub1 - the new value for the first subproblem of this one.

setSub2

public void setSub2(Hanoi sub2)
Determines the second subproblem for this problem.
Parameters:
sub1 - the new value for the second subproblem of this one.