Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

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

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Inductive Databases And Constraint Based Data Mining

Authors: Saso Dzeroski ,Bart Goethals ,Pance Panov

2010th Edition

1489982175, 978-1489982179

More Books

Students explore these related Databases questions