Advertisement
elena1234

How to create class Egine

Apr 9th, 2021
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.00 KB | None | 0 0
  1. using Telephony.Exceptions;
  2. using Telephony.IO;
  3.  
  4. namespace Telephony.Core
  5. {
  6.     public class Engine : IEngine
  7.     {
  8.         private IReader reader; // private reader;
  9.         private IWriter writer; // private writer
  10.  
  11.         private StationaryPhone stationaryPhone;
  12.         private Smartphone smartphone;
  13.         private Engine() // private constructor
  14.         {
  15.             this.stationaryPhone = new StationaryPhone();
  16.             this.smartphone = new Smartphone();
  17.         }
  18.  
  19.         public Engine(IReader reader, IWriter writer) // public constructor with reader and writer
  20.             : this()
  21.         {
  22.             this.reader = reader;
  23.             this.writer = writer;
  24.         }
  25.  
  26.         public void Run()
  27.         {
  28.             string[] phoneNumbers = reader.ReadLine().Split(" ");
  29.             string[] allSites = reader.ReadLine().Split(" ");
  30.  
  31.             foreach (var number in phoneNumbers)
  32.             {
  33.                 try
  34.                 {
  35.                     if (number.Length == 10)
  36.                     {
  37.                         writer.WriteLine(smartphone.CallOtherPhone(number));
  38.                     }
  39.  
  40.                     else if (number.Length != 10)
  41.                     {
  42.                         writer.WriteLine(stationaryPhone.CallOtherPhone(number));
  43.                     }
  44.  
  45.                     else
  46.                     {
  47.                         throw new InvalidNumberException();
  48.                     }
  49.                 }
  50.  
  51.                 catch (InvalidNumberException exception)
  52.                 {
  53.                     writer.WriteLine(exception.Message);
  54.                 }
  55.             }
  56.  
  57.             foreach (var URL in allSites)
  58.             {
  59.                 try
  60.                 {
  61.                     writer.WriteLine(smartphone.BrowseInWeb(URL));
  62.                 }
  63.  
  64.                 catch (InvalidURLException exception)
  65.                 {
  66.                     writer.WriteLine(exception.Message);
  67.                 }
  68.             }
  69.         }
  70.     }
  71. }
  72.  
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement