|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--jeops.examples.hanoi.Hanoi
This class models an encapsulation for a solution for the Towers of Hanoi problem.
Field Summary | |
private int |
destination
The pin the disks have to be moved to. |
private int |
discs
The number of discs in this problem. |
private boolean |
ok
Flag which indicates whether this problem is solved. |
private java.lang.String |
solution
The problem solution, made up by a Strings in the form "Disk moved from |
private int |
source
The pin from where the discs come. |
private Hanoi |
sub1
The first subproblem used to solve this problem. |
private Hanoi |
sub2
The second subproblem used to solve this problem. |
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. |
private void |
dump(int spaces)
Prints the tree for this instance of the Hanoi problem. |
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. |
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. |
boolean |
isOk()
Returns the state of this problem. |
void |
printSolution()
Prints the tree for this instance of the Hanoi 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. |
java.lang.String |
toString()
Returns a string representation of this object. |
Methods inherited from class java.lang.Object |
|
Field Detail |
private int discs
private int source
private int destination
private Hanoi sub1
private Hanoi sub2
private boolean ok
private java.lang.String solution
Constructor Detail |
public Hanoi(int numDiscs, int source, int destination)
numDiscs
- the number of the discs for this instance.source
- the source pindestination
- the destination pinMethod Detail |
public void addMove(int from, int to)
from
- the pin from where the disc is moved.to
- the pin to where the disc is moved.public void printSolution()
private void dump(int spaces)
spaces
- the identation for the printed output.public int getDestination()
public int getDiscs()
public int getIntermediate()
public boolean isOk()
true
if this problem has already been
solved; false
otherwise.public int getSource()
public Hanoi getSub1()
public Hanoi getSub2()
public void setOk(boolean newValue)
newValue
- the new value for the state of this problem.public void setSub1(Hanoi sub1)
sub1
- the new value for the first subproblem of this one.public void setSub2(Hanoi sub2)
sub1
- the new value for the second subproblem of this one.public java.lang.String toString()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |