Question: This here is a Tower of Hanoi java program I started. However, I need help on inputing something to where I can place the disks

This here is a Tower of Hanoi java program I started. However, I need help on inputing something to where I can place the disks into different rods with a user interaction, while also using linked nodes. Below I have my starter code, as well as the needed output.

//TowerOfHanoi class

public class TowerOfHanoi {

public static void main(String[] args){

Stack rod1 = new Stack();

Stack rod2 = new Stack();

Stack rod3 = new Stack();

rod1.push(3);

rod1.push(2);

rod1.push(1);

System.out.println(rod1);

System.out.println(rod2);

System.out.println(rod3);

}

}

Sample output:

stack 1: [3, 2, 1]

stack 2: [ ]

stack 3: [ ]

Choose a tower to move FROM: ("1 - 3")

1

Choose a tower to move TO: ("1 - 3")

2

stack 1: [3, 2]

stack 2: [1]

stack 3: [ ]

Would you like to move another disk? (y/n)

y

Choose a tower to move FROM: ("1 - 3")

1

Choose a tower to move TO: ("1 - 3")

3

stack 1: [3]

stack 2: [1]

stack 3: [2]

Would you like to move another disk? (y/n)

n

Process finished with exit code 0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!