-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTowerofHanoi.java
More file actions
66 lines (55 loc) · 1.86 KB
/
TowerofHanoi.java
File metadata and controls
66 lines (55 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import java.util.Scanner;
public class TowerofHanoi {
ArrayStack tower1;
ArrayStack tower2;
ArrayStack tower3;
int optimalMoves = 2;
int moves;
public TowerofHanoi() {}
public void startMenu() {
System.out.print("Insert number of discs: ");
int nod = new Scanner(System.in).nextInt();
for(int i = 0; i < nod; i++) {
optimalMoves += optimalMoves -1;
}
tower1 = new ArrayStack(nod);
tower2 = new ArrayStack(nod);
tower3 = new ArrayStack(nod);
displayDiscs();
System.out.println()
}
public void choose() {
switch(selectionOne()) {
case 1:
System.out.println()
}
}
public int selectionOne() {
System.out.println("Select disc to move. \n1. tower 1 disc\n2. tower 2 disc\n3. tower 3 disc");
int discS = new Scanner(System.in).nextInt();
choose();
}
public int selectionTwo() {
System.out.print("Select the tower to insert the disc into. \n1. tower 1\n tower 2\n3. tower 3\nPlease select your option. ");
int towerS = new Scanner(System.in).nextInt();
}
public void displayDiscs() {
if(tower1.isEmpty())
System.out.println("Tower 1 is empty.");
else System.out.println("Tower 1 has "+tower1.size()+" discs.");
if(tower2.isEmpty())
System.out.println("Tower 2 is empty.");
else System.out.println("Tower 2 has "+tower2.size()+" discs.");
if(tower3.isEmpty())
System.out.println("Tower 3 is empty.");
else System.out.println("Tower 3 has "+tower3.size()+" discs.");
}
public void displayOM() {
System.out.println("The optimal number of moves is: "+optimalMoves);
}
}
class main {
public static void main(String[] args) {
new TowerofHanoi().startMenu();
}
}