Exemplo n.º 1
0
        static void Main(string[] args)
        {
            string input = string.Empty;
            PrimitiveCalculator calculator = new PrimitiveCalculator();

            while ((input = Console.ReadLine()) != "End")
            {
                string[] operands = input.Split(' ');
                if (operands[0] == "mode")
                {
                    char operand = operands[1][0];
                    calculator.ChangeStrategy(operand);
                }
                else
                {
                    int firstOperand  = int.Parse(operands[0]);
                    int secondOperand = int.Parse(operands[1]);
                    Console.WriteLine(calculator.PerformCalculation(firstOperand, secondOperand));
                }
            }
            Console.ReadLine();
        }
    static void Main()
    {
        PrimitiveCalculator calculator  = new PrimitiveCalculator();
        IStrategy           newStrategy = new AdditionStrategy();
        string input = Console.ReadLine();

        while (input != "End")
        {
            string[] commandInfo = input.Split();
            if (commandInfo[0] == "mode")
            {
                switch (commandInfo[1][0])
                {
                case '+':
                    newStrategy = new AdditionStrategy();
                    break;

                case '-':
                    newStrategy = new SubtractionStrategy();
                    break;

                case '/':
                    newStrategy = new DivisionStrategy();
                    break;

                case '*':
                    newStrategy = new MultiplicationStrategy();
                    break;
                }
                calculator.ChangeStrategy(newStrategy);
            }
            else
            {
                int result = calculator.PerformCalculation(int.Parse(commandInfo[0]), int.Parse(commandInfo[1]));
                Console.WriteLine(result);
            }
            input = Console.ReadLine();
        }
    }
Exemplo n.º 3
0
    static void Main(string[] args)
    {
        var calculator = new PrimitiveCalculator();

        var input = "";

        while ((input = Console.ReadLine()) != "End")
        {
            var cmdArgs = input.Split(' ', StringSplitOptions.RemoveEmptyEntries);

            if (cmdArgs[0] == "mode")
            {
                calculator.ChangeStrategy(char.Parse(cmdArgs[1]));
            }
            else
            {
                var firstOperand = int.Parse(cmdArgs[0]);
                var secondOprand = int.Parse(cmdArgs[1]);
                Console.WriteLine(calculator.PerformCalculation(firstOperand, secondOprand));
            }
        }
    }
Exemplo n.º 4
0
    public static void Main(string[] args)
    {
        var calc = new PrimitiveCalculator();

        string input;

        while ((input = Console.ReadLine()) != "End")
        {
            var paramArgs = input.Split(' ');
            var first     = paramArgs[0];
            var second    = paramArgs[1];

            if (first == "mode")
            {
                calc.ChangeStrategy(char.Parse(second));
            }
            else
            {
                Console.WriteLine(calc.PerformCalculation(int.Parse(first), int.Parse(second)));
            }
        }
    }
Exemplo n.º 5
0
    static void Main()
    {
        var calculator = new PrimitiveCalculator(new AdditionStrategy());

        var input = Console.ReadLine().Split();

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

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

            input = Console.ReadLine().Split();
        }
    }
        public void PrimitiveCalculatorTest()
        {
            PrimitiveCalculator pc = new PrimitiveCalculator("TD2");

            TestTools.RunLocalTest("A6", pc.Process, "TD2");
        }
Exemplo n.º 7
0
 public Engine(PrimitiveCalculator calculator)
 {
     this.calculator = calculator;
 }
Exemplo n.º 8
0
 public Engine()
 {
     this.calculator = new PrimitiveCalculator();
 }