Пример #1
0
        public void RemoveDigit()
        {
            if (!_state.Input.HasValue)
            {
                return;
            }

            if (_state.JustEvaluated)
            {
                _state = new CalculatorState();
            }
            else
            {
                if (_state.Input < 10)
                {
                    _state.Input = null;
                }
                else
                {
                    _state.Input /= 10;
                }

                _state.JustEvaluated = false;
            }

            SetOutput(_state.Input);
        }
Пример #2
0
        public void AppendDigit(int digit)
        {
            if (_state.JustEvaluated)
            {
                _state = new CalculatorState();
            }

            if (!_state.Input.HasValue)
            {
                _state.Input = digit;
            }
            else if (_state.Input <= AppendLimit)
            {
                _state.Input = _state.Input * 10 + digit;
            }

            _state.JustEvaluated = false;
            SetOutput(_state.Input);
        }
Пример #3
0
 public void Reset()
 {
     _state = new CalculatorState();
     SetOutput(PaddingChar.ToString());
 }