Esempio n. 1
0
        public static void Main()
        {
            PrimitiveCalculator calculator = new PrimitiveCalculator();

            while (true)
            {
                string[] input = Console.ReadLine().Split();

                if (input[0] == "End")
                {
                    break;
                }
                else if (input[0] == "mode")
                {
                    calculator.ChangeStrategy(input[1][0]);
                }
                else
                {
                    Console.WriteLine(calculator.PerformCalculation(int.Parse(input[0]), int.Parse(input[1])));
                }
            }
        }
Esempio n. 2
0
        public static void Main()
        {
            PrimitiveCalculator calculator = new PrimitiveCalculator(new AdditionStrategy());

            string[] input = Console.ReadLine().Split();

            while (!input[0].Equals("End"))
            {
                if (input[0].Equals("mode"))
                {
                    calculator.ChangeStrategy(char.Parse(input[1]));
                }
                else
                {
                    int firstNum  = int.Parse(input[0]);
                    int secondNum = int.Parse(input[1]);

                    Console.WriteLine(calculator.PerformCalculation(firstNum, secondNum));
                }

                input = Console.ReadLine().Split();
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            var calculator = new PrimitiveCalculator(GenerateStrategyMap());

            var input = "";

            while ((input = Console.ReadLine()) != "End")
            {
                if (input.StartsWith("mode"))
                {
                    var strategy = input.Split()[1][0];
                    calculator.ChangeStrategy(strategy);
                }

                else
                {
                    var numbers = input.Split().Select(int.Parse).ToArray();

                    var result = calculator.PerformCalculation(numbers[0], numbers[1]);
                    Console.WriteLine(result);
                }
            }
        }