示例#1
0
        static void Main(string[] args)
        {
            CommandInputParser commandInputParser = new CommandInputParser();
            Calculator         calculator         = new Calculator();

            while (true)
            {
                Console.Write("Operation: ");
                string command = Console.ReadLine();

                try
                {
                    CommandTypes commandType = commandInputParser.ParseCommand(command);

                    Console.Write("Value 1: ");
                    int x = int.Parse(Console.ReadLine());

                    Console.Write("Value 2: ");
                    int y = int.Parse(Console.ReadLine());

                    int result = calculator.Calculate(commandType, x, y);

                    Console.WriteLine("Result: " + result);
                }
                catch (Exception)
                {
                    Console.WriteLine("Mistake!");
                }
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            CommandInputParser commandInputParser = new CommandInputParser();
            Calculator         calculator         = new Calculator();
            InputService       inputService       = new InputService();

            while (true)
            {
                string command = inputService.ReadCommand();

                try
                {
                    CommandTypes commandType = commandInputParser.ParseCommand(command);

                    int[] arguments = inputService.ReadArguments();

                    int result = calculator.Calculate(commandType, arguments[0], arguments[1]);

                    Console.WriteLine("Result: " + result);
                }
                catch (Exception)
                {
                    Console.WriteLine("Mistake!");
                }
            }
        }
 public CalculatorReplLoop()
 {
     commandInputParser = new CommandInputParser();
     calculator         = new Calculator();
     inputService       = new InputService();
     outputService      = new OutputService();
 }