Exemplo n.º 1
0
        static void Main()
        {
            Console.WriteLine("enter first number");
            string input = Console.ReadLine();
            double num1, num2;
            bool   result = Double.TryParse(input, out num1);

            if (!result)
            {
                Console.WriteLine("enter a number");
                return;
            }
            Console.WriteLine("enter second number");

            result = Double.TryParse(Console.ReadLine(), out num2);
            if (!result)
            {
                Console.WriteLine("enter a number");
                return;
            }
            Console.WriteLine("Enter Add,Divide");
            CalculateFactory factory = new CalculateFactory();
            ICalculate       obj     = factory.GetCalculate(Console.ReadLine());

            obj.Calculate(num1, num2);
            Main();
        }
Exemplo n.º 2
0
        static void Main(string[] args = null)
        {
            double num1, num2;

            Console.WriteLine("Enter first number ?");
            var result1 = double.TryParse(Console.ReadLine(), out num1);

            if (!result1)
            {
                Console.WriteLine("Enter a number !!");
                return;
            }

            Console.WriteLine("Enter second number ?");
            var result2 = double.TryParse(Console.ReadLine(), out num2);

            if (!result2)
            {
                Console.WriteLine("Enter a number !!");
                return;
            }

            Console.WriteLine("Choose calcualtion method (Add/Substract/Divide");
            // Base classs = derive class object
            // Return selected object to execute relevent task  (e.g. Add)
            var calObject = new CalculateFactory().GetCalculation(Console.ReadLine());

            calObject.Calculate(num1, num2);

            Console.ReadLine();
            Console.Clear();

            Main();
        }