예제 #1
0
파일: Engine.cs 프로젝트: yordanov1/SoftUni
 private void CallNumbers(string[] phoneNumbers)
 {
     foreach (var number in phoneNumbers)
     {
         try
         {
             if (number.Length == 7)
             {
                 writer.WriteLine(stationaryPhone.Call(number));
             }
             else if (number.Length == 10)
             {
                 writer.WriteLine(smartphone.Call(number));
             }
             else
             {
                 throw new InvalidNumberException();
             }
         }
         catch (InvalidNumberException ine)
         {
             writer.WriteLine(ine.Message);
         }
     }
 }
        public void Run()
        {
            string[] phoneNumbers = reader.ReadLine()
                                    .Split(' ').ToArray();
            string[] sites = reader.ReadLine()
                             .Split(' ').ToArray();

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

            foreach (var url in sites)
            {
                try
                {
                    writer.WriteLine(smartphone.Browse(url));
                }
                catch (InvalidUrlException iue)
                {
                    writer.WriteLine(iue.Message);
                }
            }
        }
예제 #3
0
        private static void PrintPhoneNumbers(List <string> phoneNumbersToCall, Smartphone smartphone, StationaryPhone stationaryPhone)
        {
            foreach (var item in phoneNumbersToCall)
            {
                if (!item.All(x => char.IsDigit(x)))
                {
                    Console.WriteLine("Invalid number!");
                    continue;
                }

                if (item.Length == 7)
                {
                    stationaryPhone.Call(item);
                }
                else
                {
                    smartphone.Call(item);
                }
            }
        }
예제 #4
0
파일: Engine.cs 프로젝트: duygu-rmdn/04.OOP
 public void CallTheNumber(string[] numbers)
 {
     foreach (var number in numbers)
     {
         try
         {
             if (number.Length == 10)
             {
                 writer.WriteLine(smartPhone.Call(number));
             }
             else
             {
                 //Console.WriteLine(stationaryPhone.Call(number));
                 writer.WriteLine(stationaryPhone.Call(number));
             }
         }
         catch (InvalidNumber ui)
         {
             writer.WriteLine(ui.Message);
         }
     }
 }
예제 #5
0
        public void Run()
        {
            string[] phoneNumbers = reader.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
            string[] sites        = reader.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);

            foreach (var number in phoneNumbers)
            {
                try
                {
                    if (number.Length <= 7)
                    {
                        writer.WriteLine(stationaryPhone.Call(number));
                    }
                    else if (number.Length >= 10)
                    {
                        writer.WriteLine(smartphone.Call(number));
                    }
                }
                catch (InvalidNumberException ine)
                {
                    writer.WriteLine(ine.Message);
                }
            }

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