-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalculatorPrompter.java
111 lines (97 loc) · 3.03 KB
/
CalculatorPrompter.java
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import java.util.Scanner;
import shapes.*;
public class CalculatorPrompter {
Scanner scanner = new Scanner(System.in);
public CalculatorPrompter() {
welcomePrint();
promptForShape();
}
private void promptForShape() {
String shapeString = scanner.nextLine();
ShapeIO shapeObject = null;
switch (shapeString) {
case "1":
case "polygon":
shapeObject = new Polygon();
break;
case "2":
case "circle":
shapeObject = new Circle();
break;
case "4":
case "cone":
shapeObject = new Cone();
break;
case "5":
case "cylinder":
shapeObject = new Cylinder();
break;
case "3":
case "pyramid":
shapeObject = new RectangularPyramid();
break;
case "6":
case "ellipse":
shapeObject = new Ellipse();
break;
case "7":
case "sphere":
shapeObject = new Sphere();
break;
}
shapeObject.getSideLengths(scanner);
shapeObject.printCalculations();
restart();
}
// if the calculation has been printed in the terminal, the calculator will ask to restart or close
public void restart() {
System.out.println("DO YOU WISH TO RESTART?");
System.out.println("-> yes");
System.out.println("-> no");
// clear out the scanner buffer
scanner.nextLine();
String answer = scanner.nextLine();
if (answer.equalsIgnoreCase("yes")) {
System.out.println("-------------CALCULATOR RESTART-------------");
addDelay(300);
System.out.println("Hello again!! Welcome back to the shape calculator :D");
welcomePrint();
promptForShape();
}
else {
scanner.close();
System.out.println("Thank you for using the shape calculator! Have a great day!");
}
}
public void welcomePrint() {
addDelay();
System.out.println("What shape would you like to analyze?");
addDelay(300);
System.out.println("We currently offer:");
addDelay();
System.out.println("1 -> polygon (regular)");
addDelay();
System.out.println("2 -> circle");
addDelay();
System.out.println("3 -> pyramid (rectangular)");
addDelay();
System.out.println("4 -> cone");
addDelay();
System.out.println("5 -> cylinder");
addDelay();
System.out.println("6 -> ellipse");
addDelay();
System.out.println("7 -> sphere");
addDelay();
}
private void addDelay() {
addDelay(600);
}
private void addDelay(long duration) {
try {
Thread.sleep(duration);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}