Пример #1
0
        static void Main(string[] args)
        {
            List <string> phoneNumbers = Console.ReadLine()
                                         .Split(' ', StringSplitOptions.RemoveEmptyEntries)
                                         .ToList();

            List <string> websites = Console.ReadLine()
                                     .Split(' ', StringSplitOptions.RemoveEmptyEntries)
                                     .ToList();

            Smartphone      smartphone = new Smartphone();
            StationaryPhone stationary = new StationaryPhone();

            foreach (string n in phoneNumbers)
            {
                if (n.Length == 10)
                {
                    Console.WriteLine(smartphone.Dial(n));
                }
                else
                {
                    Console.WriteLine(stationary.Dial(n));
                }
            }

            foreach (string site in websites)
            {
                Console.WriteLine(smartphone.Browse(site));
            }
        }
Пример #2
0
        public static void Run()
        {
            // Read phone numbers and website urls
            var numbers = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
            var urls    = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();

            var smartPhone      = new SmartPhone();
            var stationaryPhone = new StationaryPhone();

            foreach (var number in numbers)
            {
                if (!IsValidNumber(number))
                {
                    Console.WriteLine("Invalid number!");
                    continue;
                }
                // Call or dial number
                switch (number.Length)
                {
                case 10:
                    smartPhone.Call(number);
                    break;

                case 7:
                    stationaryPhone.Dial(number);
                    break;

                default:
                    Console.WriteLine("Invalid number!");
                    break;
                }
            }

            foreach (var url in urls)
            {
                // Validate URL
                if (!IsValidURL(url))
                {
                    Console.WriteLine("Invalid URL!");
                    continue;
                }

                smartPhone.Browse(url);
            }
        }
Пример #3
0
        static void Main(string[] args)
        {
            StationaryPhone phone      = new StationaryPhone();
            Smartphone      smartPhone = new Smartphone();

            var    numbers = Console.ReadLine().Split(" ");
            var    sites   = Console.ReadLine().Split(" ");
            string x       = "^[0-9]*$";

            //string y = @"[a-zA-Z._^%$#!~@,-]";

            foreach (var n in numbers)
            {
                if (!Regex.IsMatch(n, x))
                {
                    Console.WriteLine("Invalid number!");
                    continue;
                }
                else
                {
                    if (n.Length == 7)
                    {
                        Console.WriteLine(phone.Dial(n));
                    }
                    if (n.Length == 10)
                    {
                        Console.WriteLine(smartPhone.Dial(n));
                    }
                }
            }

            foreach (var s in sites)
            {
                if (s.FirstOrDefault(c => char.IsDigit(c)) != 0)
                {
                    Console.WriteLine("Invalid URL!");
                    continue;
                }
                Console.WriteLine(smartPhone.Browse(s));
            }
        }