Last week, you have created TowerOfHanoi.java which can be used to represents a Tower of Hanoi
puzzle. This week, you have to solve Tower of Hanoi puzzles using recursion.
What to do
In the file THSolverFrame.java, you will find a main function and a method named solveTower().
The main function is as follows:
public static void main(String args) throws InterruptedException
TowerOfHanoi towers = new TowerOfHanoi(10);
THComponent thc = new THComponent(towers);
JFrame frame = new JFrame();
frame.setTitle(“Tower of Hanoi”);
//solveTower(towers, thc, …);
Note that the second to last line is commented out. It calls a method named solveTower() with
incomplete number of arguments. You job is to finish the method solveTower() (marked TO DO)
using the algorithm discussed in class. Similarly, the signature of the starting code for the method
solveTower is incomplete. DO NOT modify the first two arguments of the method solveTower().
They must be TowerOfHanoi and THComponent. This will allow you to see the animation of solving
the Tower of Hanoi.
To see the animation, every time your method calls the method moveTopDisc() of the TowerOfHanoi,
you have to call thc.repaint(); follows by Thread.sleep(100);. Note that the default number
of discs is 10. You can change it by simply change the value of numberOfDiscs in the main method.
CS/COE 0445 — Data Structure Page 1
Lab 7: Tower of Hanoi Solver
There is no test class for this lab. We will test by looking at the animation.
Due Date and Submission
For the due date, please check the lab in the CourseWeb. Submit your THSolverFrame.java to
the CourseWeb under this lab by the due date. No late submission will be accepted.