-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMain.java
More file actions
78 lines (70 loc) · 1.95 KB
/
Main.java
File metadata and controls
78 lines (70 loc) · 1.95 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
package boundary;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import control.*;
import entity.*;
public class Main {
private static Polynomial polynomial_now;
private static InputStreamReader isr = new InputStreamReader(System.in);
private static BufferedReader reader = new BufferedReader(isr);
public static void main(String[] args) throws IOException{
String input;
int cls=0;
Derivative dervative=null;
Expression expression=null;
Simplify simplify=null;
while (true){
input=acceptInput();
cls=judge(input);
if (cls==1){
expression=new Expression(input);
int rs=expression.handle();
if (rs==1){
polynomial_now=expression.getPolynomial();
}
showResult(rs);
}
else if (cls==2){
simplify=new Simplify(polynomial_now,input);
int rs=simplify.handle();
showResult(rs);
}
else if (cls==3){
dervative=new Derivative(polynomial_now,input);
int rs=dervative.handle();
showResult(rs);
}
else{
showResult(-1);
}
}
}
public static String acceptInput() throws IOException{
System.out.print(">");
String input="";
if ((input = reader.readLine()) != null ){
return input;
}
else
return null;
}
public static void showResult(int cls){
if (cls==1)
System.out.print("\n>");
else if (cls==-1){
System.out.println("Input Error!");
System.out.print("\n>");
}
}
public static int judge(String input){
if (!input.startsWith("!"))
return 1;
else if (input.startsWith("!simplify "))
return 2;
else if (input.startsWith("!d/d "))
return 3;
else
return 0;
}
}