MCPcopy Create free account
hub / github.com/Aghajari/MathParser / main

Method main

MathParser/src/com/aghajari/Main.java:12–45  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

10public class Main {
11
12 public static void main(String[] args) throws MathParserException {
13 Scanner scanner = new Scanner(System.in);
14 MathParser parser = MathParser.create();
15
16 for (; ; ) {
17 String line = scanner.nextLine().trim();
18 if (line.isEmpty())
19 continue;
20
21 if (isExp(line)) {
22 parser.addExpression(line);
23
24 } else {
25 try {
26 System.out.println("\n" + parser.parse(line));
27
28 } catch (MathParserException e) {
29 if (e instanceof MathVariableNotFoundException) {
30 System.out.println(e.getMessage());
31 continue;
32 }
33 e.printStackTrace();
34 return;
35 }
36 break;
37 }
38 }
39
40 if (!parser.getVariables().isEmpty()) {
41 System.out.println("Variables:");
42 for (MathParser.MathVariable variable : parser.getVariables())
43 System.out.println(variable.getName() + " = " + variable.getExpression() + " = " + variable.getAnswer());
44 }
45 }
46
47 public static boolean isExp(String line) {
48 if (line.contains("=")) {

Callers

nothing calls this directly

Calls 9

createMethod · 0.95
isExpMethod · 0.95
addExpressionMethod · 0.95
parseMethod · 0.95
getVariablesMethod · 0.95
trimMethod · 0.80
getNameMethod · 0.80
getExpressionMethod · 0.80
getAnswerMethod · 0.80

Tested by

no test coverage detected