コード例 #1
0
ファイル: StartUp.cs プロジェクト: viewless/SoftUni
        static void Main(string[] args)
        {
            string[] input    = Console.ReadLine().Trim().Split();
            string[] urlInput = Console.ReadLine().Trim().Split();

            ICallable  smartphone      = new Smartphone();
            ICallable  stationaryPhone = new StationaryPhone();
            IBrowsable browsable       = new Smartphone();


            for (int i = 0; i < input.Length; i++)
            {
                if (input[i].Length < 10)
                {
                    Console.WriteLine(stationaryPhone.Call(input[i]));
                }
                else
                {
                    Console.WriteLine(smartphone.Call(input[i]));
                }
            }

            for (int i = 0; i < urlInput.Length; i++)
            {
                Console.WriteLine(browsable.Browse(urlInput[i]));
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            string[]        numbers         = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
            string[]        sites           = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
            Smartphone      smartphone      = new Smartphone();
            StationaryPhone stationaryPhone = new StationaryPhone();

            foreach (var number in numbers)
            {
                try
                {
                    if (number.Length == 10)
                    {
                        Console.WriteLine(smartphone.Call(number));
                    }
                    else if (number.Length == 7)
                    {
                        Console.WriteLine(stationaryPhone.Call(number));
                    }
                    else
                    {
                        throw new InvalidNumberException();
                    }
                }
                catch (InvalidNumberException ine)
                {
                    Console.WriteLine(ine.Message);
                }
            }

            foreach (var url in sites)
            {
                try
                {
                    Console.WriteLine(smartphone.Browse(url));
                }
                catch (InvalidURLException iurle)
                {
                    Console.WriteLine(iurle.Message);
                }
            }
        }