-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUserInterface.java
More file actions
70 lines (64 loc) · 1.66 KB
/
UserInterface.java
File metadata and controls
70 lines (64 loc) · 1.66 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
/*
* DSA II Mini Project - Scientific Calculator
Team members:
2328 - Shruti Datar
2329 - Samruddhi Deode
2332 - Nisha Deshmukh
2336 - Yamini Dongaonkar
Problem Statement :
Creating a scientific calculator to solve arithmetic,
trigonometric and logarithmic expressions;
to store and process variables and functions.
*/
package calc;
import java.util.Scanner;
public class UserInterface {
public static void main(String[] args) {
HashTable hash = new HashTable();
Calculator c = new Calculator(hash);
Scanner sc = new Scanner(System.in);
String ans = "";
System.out.println("Welcome!");
while(true) {
System.out.print(">>> ");
String exp = sc.nextLine();
if(exp.equalsIgnoreCase("Exit")) {
System.out.println("Thank you!");
break;
}
ans = c.calculate(exp);
if (!ans.isBlank())
System.out.println(ans);
}
}
}
class Calculator {
HashTable hash;
Calculator(HashTable h){
hash = h;
}
public String calculate(String exp) {
String e= "";
FileHandler fh = new FileHandler();
AssignmentHandler ah = new AssignmentHandler();
FunctionHandler funchand = new FunctionHandler();
ExpressionHandler exphand = new ExpressionHandler();
if(exp.contains("import")) {
e = fh.fileHandle(exp,hash);
}
else if(exp.contains("=") && !exp.contains("Func")) {
//call assignment handler
e = ah.assign(exp,hash);
}
else if(exp.contains("Func") ) {
//call function handler
e = funchand.handle(exp, hash);
}
else if(exp.isBlank())
e = "";
else { //call expression handler
e = exphand.evaluate(exp,hash);
}
return e;
}
}