예제 #1
0
        public void DigitButtonPress(string button)
        {
            switch (button)
            {
            case "CLEAR":
            {
                Display      = "0";
                LeftOperand  = string.Empty;
                RightOperand = string.Empty;
                Operation    = string.Empty;
                break;
            }

            case "BACKSPACE":
            {
                if (Operation != string.Empty && RightOperand == string.Empty)
                {
                    Operation = string.Empty;
                    Display   = LeftOperand;
                }
                else if (Operation != string.Empty && RightOperand != string.Empty)
                {
                    RightOperand = RightOperand.Remove(RightOperand.Length - 1);
                    Display      = LeftOperand + Operation + RightOperand;
                }
                else if (LeftOperand != string.Empty)
                {
                    LeftOperand = LeftOperand.Remove(LeftOperand.Length - 1);
                    if (LeftOperand != string.Empty)
                    {
                        Display = LeftOperand;
                    }
                    else
                    {
                        Display = "0";
                    }
                }
                break;
            }

            default:
            {
                if (Operation == string.Empty)
                {
                    LeftOperand = LeftOperand + button;
                    Display     = LeftOperand;
                }
                else
                {
                    RightOperand = RightOperand + button;
                    Display      = LeftOperand + Operation + RightOperand;
                }

                break;
            }
            }
        }