(String[] args)
| 10 | public 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("=")) { |
nothing calls this directly
no test coverage detected