Пример #1
0
        public void insertOP(OPERATION op)
        {
            double res;

            Double.TryParse(currentBuffer, out res);

            if (op == OPERATION.NEG)
            {
                res   = -res;
                total = res;
                calcWindow.onCurrentValueChange(total.ToString());
                return;
            }

            if (active_op == OPERATION.NULL)
            {
                total += res;
                calcWindow.onCurrentValueChange(total.ToString());
                active_op = op;
                state     = STATE.INSERT_BINARY_OP;
                return;
            }

            switch (active_op)
            {
            case OPERATION.ADD:
                total += res;
                break;

            case OPERATION.SUB:
                total -= res;
                break;

            case OPERATION.DIV:
                total /= res;
                break;

            case OPERATION.MUL:
                total *= res;
                break;
            }

            active_op = op;

            calcWindow.onCurrentValueChange(total.ToString());
            state = STATE.INSERT_BINARY_OP;
        }
Пример #2
0
 public Calculator(CalculatorWindow win)
 {
     calcWindow = win;
     win.onCurrentValueChange(currentBuffer);
     history = new LinkedList <string>();
 }