Want to write tests for thsese methods in Java package towerOfHanoi; import java.util.Observable; public class HanoiSolver extends Observable { private Tower left; private Tower middle;
Want to write tests for thsese methods in Java
package towerOfHanoi;
import java.util.Observable;
public class HanoiSolver extends Observable {
private Tower left;
private Tower middle;
private Tower right;
private int numDiscs;
public HanoiSolver(int numDiscs) {
left = new Tower();
middle = new Tower();
right = new Tower();
this.numDiscs = numDiscs;
}
public Tower getTower(Position pos) {
switch (pos) {
case LEFT:
return left;
case RIGHT:
return right;
case MIDDLE:
return middle;
default:
return left;
}
}
public int numDiscs() {
return numDiscs;
}
/**
*
*
*/
public void move(Tower source, Tower destination) {
destination.push(source.pop());
setChanged();
notifyObservers(destination.postion());
}
/**
*
*/
public void solveTowers(
int currentDiscs,
Tower startPole,
Tower tempPole,
Tower endPole) {
if (currentDiscs == 1) {
move(startPole, endPole);
}
else {
solveTowers(currentDiscs - 1, startPole, endPole, tempPole);
move(startPole, endPole);
solveTowers(currentDiscs - 1, endPole, tempPole, startPole);
}
}
/**
*
*/
public void solve() {
solveTowers(numDiscs, left, middle, right);
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started