Question
Please proof this code to make this problem work (in Java) package TowersOfHanoi; import java.util.Scanner; public class TowersOfHanoi { private Scanner in; private int n,
Please proof this code to make this problem work (in Java)
package TowersOfHanoi; import java.util.Scanner; public class TowersOfHanoi { private Scanner in; private int n, current, r; private int[] hasItMoved, toDest; Towers() { this.in=new Scanner(System.in) this.current=1; System.out.pringtln("Enter the number of disks: "); /umber of disks this.current = in.nextInt(); this.hasItMoved=new int[12]; this.toDest = new int[12]; for(int j=0; j public void TowersOfHanoi(int numOfDisks, String Start, String source, String dest, String aux, String last, int current) //recursive function to manipulate the disks { move(1, Start, source, this.current) this.current++; //call for move function H1(n, "Start", "Aux1", "Aux3", "Aux2", "Dest", this.current) //call for the recursive fuction move(1, dest, last, this.current) this.current++; //call for move function } public int H1(int numOfDisks, String Start, String source, String dest, String aux, String last, int current) { if(numOfDisks == 1) //scenario if num of disks are equal to two { move(numOfDisks, source, aux, this.current) this.curreent++; move(numOfDisks, aux, dest, this.current) this.current++; } else if (numOfDisks == 2) //scenario if there are two disks { move(numOfDisks, source, aux, this.current) this.curreent++; move(numOfDisks, aux, dest, this.current) this.current++; if(this.current==4) { move(numOfDisks, Start, source, this.current) this.current++; } move(numOfDisks, source, aux, this.current) this.current++; move(numOfDisks-1, dest, aux, this.current) this.current++; move(numOfDisks-1, aux, source, thisi.current); this.current++; move(numOfDisks, aux, dest, this.current) this.current++; if(this.current==2) { move(2, dest, last, this.current) this.current++; } move(numOfDisks-1, source, aux, this.current); this.current++; move(numOfDisks-1, aux, dest, this.current) this.current++; } else if (numOfDisks > 2) //scenario if the number of disks are greater than 2 this.current = H1(numOfDisks-1, Start, source, dest, aux, last, this.current) if(this.hasItMoved[numOfDisks]!=1) { move(numOfDisks, Start, source, this.current) this.current++; this.hasItMoved[numOfDisks]=1; } move(numOfDisks, source, aux, this.current) this.current++; this.current = H1(numOfDisks-1, Start, dest, source, aux, last, this.current) move(numOfDisks, dest, last, this.current) this.current++; this.toDest[numOfDisks]=1; } if(numOfDisks==r) this.r--; this.current = H1(numOfDisks-1; Start, source, dest, aux, last, this.current); }; return ths.current; } //Printing out the moves of the Towers of Hanoi public void move(int aDisk, String source, String dest, int currentStep) { public void move(int aDisk, String source, String dest, int currentStep) { System.out.prinln("Move " + this.current +": Move disk " + aDisk + " from " + source + " to " + dest); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
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