package com.celci2015;

import com.celci2015.math.MathExpression;

/**
 * Created by pablo on 9/7/15.
 */
public abstract class UserInterface {

    public static final String OPERATION = "\\ ([+*-]|[e])\\ ";
    public static final String expressionPattern = "(-\\d+|\\d+)\\ (-\\d+|\\d+)\\ (-\\d+|\\d+)(\\ \\|\\ (-\\d+|\\d+)\\ (-\\d+|\\d+)\\ (-\\d+|\\d+))*\\ (([+*-]\\ (-\\d+|\\d+)\\ (-\\d+|\\d+)\\ (-\\d+|\\d+)(\\ \\|\\ (-\\d+|\\d+)\\ (-\\d+|\\d+)\\ (-\\d+|\\d+))*)|([e]\\ (-\\d+|\\d+)\\ (-\\d+|\\d+)))";
    public static final String BAD_INPUT = "Bad input!";

    public abstract void display(String result);
    public void query(String queryString)
    {
        if (!queryString.matches(expressionPattern)) {
            if (queryString.matches(Processor.expressionPattern))
            {
                display(queryString);
              return;
            }
            display(BAD_INPUT);
            return;
        }
        String[] inputs = queryString.split(OPERATION);
        MathExpression expression;
        try{
        switch (queryString.charAt(inputs[0].length() + 1)) {// get operation
            case '*':
                expression = new MathExpression(inputs[0]);
                expression.times(new MathExpression(inputs[1]));
                display(expression.toString());
                break;
            case '+':
                expression = new MathExpression(inputs[0]);
                expression.add(new MathExpression(inputs[1]));
                display(expression.toString());
                break;
            case '-':
                expression = new MathExpression(inputs[0]);
                expression.minus(new MathExpression(inputs[1]));
                display(expression.toString());
                break;
            case 'e':
                String[] xy = inputs[1].split(" ");
                int x = Integer.parseInt(xy[0]);
                int y = Integer.parseInt(xy[1]);
                display(new MathExpression(inputs[0]).eval(x,y) +" 0 0");
                break;
            default:
                throw new Exception("Wrong Operation");
        }}
        catch(Exception e)
        {
            e.printStackTrace();
            display(BAD_INPUT +" "+ e.getMessage());

        }
    }
}

@@ -202,16 +202,127 @@
 %5D)%5C%5C %22;%0A
+    //Pattern this form : # # # %7C # # # %7C .... operation # # # %7C # # # .... where operation can be *,+,- or e.%0A
     publ
@@ -820,16 +820,37 @@
 tern)) %7B
+// Verify expression 
 %0A       
@@ -907,16 +907,52 @@
 attern))
+// verify is its a single expression
 %0A       
@@ -1198,16 +1198,125 @@
    try%7B%0A
+            //First we get the operation, then parse a math expression and then execute the other expression%0A
         
@@ -2443,16 +2443,18 @@
         
+//
 e.printS
@@ -2518,16 +2518,41 @@
 sage());
+// Display error messagee
 %0A%0A      

Update UserInterface.java