Esempio n. 1
0
        public static void Main()
        {
            IStrategy   defaultStrategy = new AdditionStrategy();
            IReader     reader          = new ConsoleReader();
            IWriter     writer          = new ConsoleWriter();
            ICalculator calc            = new PrimitiveCalculator(defaultStrategy);

            Engine engine = new Engine(reader, writer, calc);

            engine.Run();
        }
Esempio n. 2
0
        public static void Main()
        {
            IReader             reader           = new ConsoleReader();
            IWriter             writer           = new ConsoleWriter();
            IStrategy           additionStrategy = new AdditionStrategy();
            IStrategyFactory    factory          = new StrategyFactory();
            PrimitiveCalculator calculator       = new PrimitiveCalculator(additionStrategy, factory);

            IRunnable engine = new Engine(calculator, reader, writer);

            engine.Run();
        }
Esempio n. 3
0
        public static void Main()
        {
            string input      = Console.ReadLine();
            var    calculator = new PrimitiveCalculator();

            while (input != "End")
            {
                string[] inputArgs = input.Split();

                if (inputArgs[0] == "mode")
                {
                    switch (inputArgs[1])
                    {
                    case "/":
                        IStrategy division = new DevisionStrategy();
                        calculator.ChangeStrategy(division);
                        break;

                    case "*":
                        IStrategy multiply = new MultipllyStrategy();
                        calculator.ChangeStrategy(multiply);
                        break;

                    case "-":
                        IStrategy substract = new SubtractionStrategy();
                        calculator.ChangeStrategy(substract);
                        break;

                    case "+":
                        IStrategy adding = new AdditionStrategy();
                        calculator.ChangeStrategy(adding);
                        break;

                    default:
                        throw new ArgumentException();
                    }
                }
                else
                {
                    int firstOperant  = int.Parse(inputArgs[0]);
                    int secondOperant = int.Parse(inputArgs[1]);
                    var result        = calculator.PerformCalculation(firstOperant, secondOperant);
                    Console.WriteLine(result);
                }

                input = Console.ReadLine();
            }
        }
Esempio n. 4
0
        public static void Main()
        {
            var input      = Console.ReadLine();
            var calculator = new PrimitiveCalculator();

            while (input != "End")
            {
                string[] inputArgs = input.Split();
                if (inputArgs[0] == "mode")
                {
                    switch (inputArgs[1][0])
                    {
                    case '/':
                        var devision = new DevisionStrategy();
                        calculator.ChangeStrategy(devision);
                        break;

                    case '*':
                        var multyplication = new MultyplicationStrategy();
                        calculator.ChangeStrategy(multyplication);
                        break;

                    case '-':
                        var substraction = new SubstractionStrategy();
                        calculator.ChangeStrategy(substraction);
                        break;

                    case '+':
                        var addition = new AdditionStrategy();
                        calculator.ChangeStrategy(addition);
                        break;
                    }
                }
                else
                {
                    int firstOperand  = int.Parse(inputArgs[0]);
                    int secondOperand = int.Parse(inputArgs[1]);

                    int result = calculator.PerformCalculation(firstOperand, secondOperand);

                    Console.WriteLine(result);
                }

                input = Console.ReadLine();
            }
        }