-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostfixCalculator.java
More file actions
52 lines (34 loc) · 1.04 KB
/
PostfixCalculator.java
File metadata and controls
52 lines (34 loc) · 1.04 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
import java.util.Scanner;
public class PostfixCalculator{
public static void main (String [] args){
Scanner sc = new Scanner(System.in);
boolean state = true;
System.out.println("\nWelcome to Jason's Infix to Postfix Calculator!");
while(state == true){
System.out.print("\nPlease enter an infix expression: ");
String input = sc.nextLine();
String postfix = Converter.toPostFix(input);
System.out.println("Postfix: " + postfix);
System.out.println("Answer: " + Calculator.evaluatePostFix(postfix));
menu();
}
}
public static void menu(){
boolean state = true;
Scanner sc = new Scanner(System.in);
while(state){
System.out.println("\nWhat would you like to do next?: \n");
System.out.println("1: Try another expression");
System.out.println("2: Exit");
System.out.print("Input: ");
String input = sc.nextLine();
if (input.equals("1")){
state = false;
} else if ( input.equals("2")){
System.exit(0);
} else {
System.out.println("Error: Invalid input");
}
}
}
}