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); } } }
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); } } }
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); } } }
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); } } }