Ejemplo n.º 1
0
        private void SetCalculationManager(out ICalculatorManager manager)
        {
            _view.DisplayMessage("Select way for calculating: " +
                                 "\npress 1 - via file; " +
                                 "\npress 2 - via console " +
                                 "\npress 0 - to exit");

            while (true)
            {
                int result = 0;
                while (!int.TryParse(_view.GetUserResponse(), out result))
                {
                    _view.DisplayMessage("Wrong number, try again.");
                }

                switch (result)
                {
                case 0:
                    manager = null;
                    return;

                case 1:
                    manager = new FileCalculator(_view);
                    return;

                case 2:
                    manager = new ConsoleCalculator(_view);
                    return;

                default:
                    manager = null;
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        public string ReadData()
        {
            string path;

            _view.DisplayMessage("Enter path to the file with operations which needs to calculate");

            do
            {
                path = _view.GetUserResponse();
            }while (!CheckIfExists(path));
            return(path);
        }
Ejemplo n.º 3
0
        public string ReadData()
        {
            _view.DisplayMessage("Calculator supports only operations of addition(+), multiplication(*), division(/) and subtraction(-). " +
                                 "\nAlso expression should not contain brackets " +
                                 "\nPlease enter expression for calculation. ");

            string expression;

            while (!Regex.IsMatch(expression = _view.GetUserResponse(), _validLineRegex))
            {
                _view.DisplayMessage("Expresion cannot be calculated. Enter valid formula.");
            }
            return(expression);
        }