Esempio n. 1
0
        public void Calling()
        {
            string[] numbers = Console.ReadLine().Split(' ').ToArray();

            for (int i = 0; i < numbers.Length; i++)
            {
                bool isNumber = false;
                for (int j = 0; j < numbers[i].Length; j++)
                {
                    if (numbers[i][j] > 47 && numbers[i][j] < 58)
                    {
                        isNumber = true;
                    }
                    else
                    {
                        Console.WriteLine("Invalid number!");
                        isNumber = false;
                        break;
                    }
                }
                if (isNumber)
                {
                    if (numbers[i].Length == 10)
                    {
                        Console.WriteLine($"Calling... {numbers[i]}");
                    }
                    else if (numbers[i].Length < 10)
                    {
                        IStationaryphone stationaryphone = new Stationaryphone();
                        stationaryphone.Calling();
                        Console.WriteLine($"Dialing... {numbers[i]}");
                    }
                }
            }
        }
        static void Main(string[] args)
        {
            string[] phones = Console.ReadLine().Split(" ");
            string[] urls   = Console.ReadLine().Split(" ");

            Smartphone      smartphone      = new Smartphone();
            Stationaryphone stationaryphone = new Stationaryphone();

            foreach (var number in phones)
            {
                try
                {
                    string result = number.Length == 10
                   ? smartphone.Call(number)
                   : stationaryphone.Call(number);

                    Console.WriteLine(result);
                }
                catch (InvalidOperationException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            foreach (var url in urls)
            {
                try
                {
                    string result = smartphone.Browse(url);
                    Console.WriteLine(result);
                }
                catch (InvalidOperationException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }