-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculatorPrompter.java
More file actions
133 lines (119 loc) · 3.41 KB
/
Copy pathCalculatorPrompter.java
File metadata and controls
133 lines (119 loc) · 3.41 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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import java.util.Scanner;
import shapes.*;
/**
* Filename: CalculatorPrompter.java
*
* @author Tina Hague
* @author Alexander Hamilton
*
* Last Updated: 17 Oct 2024
*/
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();
}
/**
* Asks the user if they would like to restart the calculator after
* completing a calculation
*/
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!");
}
}
/**
* Prints all available options of the calculator
*/
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();
}
/**
* Adds a delay of 600 milliseconds
*/
private void addDelay() {
addDelay(600);
}
/**
* Adds a delay for a the given duration of milliseconds
*
* @param duration
*/
private void addDelay(long duration) {
try {
Thread.sleep(duration);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}