Beispiel #1
0
        public void OperationButtonPress(string button)
        {
            if (LeftOperand != string.Empty)
            {
                switch (button)
                {
                case "+":
                {
                    if (RightOperand != string.Empty)
                    {
                        _calculatorModel.CalculateResult();
                        Operation    = "+";
                        LeftOperand  = _calculatorModel.Result;
                        RightOperand = String.Empty;
                    }
                    else
                    {
                        Operation = "+";
                    }
                    Display = LeftOperand + Operation;
                    break;
                }

                case "-":
                {
                    if (RightOperand != string.Empty)
                    {
                        _calculatorModel.CalculateResult();
                        Operation    = "-";
                        LeftOperand  = _calculatorModel.Result;
                        RightOperand = String.Empty;
                    }
                    else
                    {
                        Operation = "-";
                    }
                    Display = LeftOperand + Operation;
                    break;
                }

                case "*":
                {
                    if (RightOperand != string.Empty)
                    {
                        _calculatorModel.CalculateResult();
                        Operation    = "*";
                        LeftOperand  = _calculatorModel.Result;
                        RightOperand = String.Empty;
                    }
                    else
                    {
                        Operation = "*";
                    }
                    Display = LeftOperand + Operation;
                    break;
                }

                case "/":
                {
                    if (RightOperand != string.Empty)
                    {
                        _calculatorModel.CalculateResult();
                        Operation    = "/";
                        LeftOperand  = _calculatorModel.Result;
                        RightOperand = String.Empty;
                    }
                    else
                    {
                        Operation = "/";
                    }
                    Display = LeftOperand + Operation;
                    break;
                }

                case "=":
                {
                    if (RightOperand != string.Empty)
                    {
                        _calculatorModel.CalculateResult();
                        Operation    = string.Empty;
                        LeftOperand  = _calculatorModel.Result;
                        RightOperand = String.Empty;
                        Display      = LeftOperand;
                    }
                    break;
                }

                default:
                    throw new ArgumentException();
                }
            }
        }