Guest User

Untitled

a guest
Dec 19th, 2016
502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using System.Runtime.InteropServices;
  6. using System.Text;
  7. using System.Text.RegularExpressions;
  8. using System.Threading.Tasks;
  9.  
  10. namespace InterfaceIPerson
  11. {
  12.     class Program
  13.     {
  14.         static void Main(string[] args)
  15.         {
  16.  
  17.  
  18.             string[] phNumbers = Console.ReadLine().Split(' ');
  19.             string[] webAddresses = Console.ReadLine().Split(' ');
  20.  
  21.             Smartphone sf = new Smartphone();
  22.             foreach (var number in phNumbers)
  23.             {
  24.                 Console.WriteLine(sf.CallOther(number));
  25.            
  26.             }
  27.             foreach (var address in webAddresses)
  28.             {
  29.                 Console.WriteLine(sf.BrowseInWeb(address));
  30.              
  31.             }
  32.         }
  33.     }
  34.  
  35.     class Smartphone : ICallable, IBrowsable
  36.     {
  37.         public string CallOther(string number)
  38.         {
  39.             string pat = @"^\d+$";
  40.             Regex reg = new Regex(pat);
  41.             if (reg.IsMatch(number))
  42.             {
  43.                 return "Calling... " + number;
  44.             }
  45.             else
  46.             {
  47.                 return "Invalid number!";
  48.             }
  49.             // is valid return Browsing: number
  50.             // not valid return Invalid URL!
  51.             throw new NotImplementedException();
  52.         }
  53.  
  54.         public string BrowseInWeb(string webAdr)
  55.         {
  56.             string pat = @"^\D+$";
  57.             Regex reg = new Regex(pat);
  58.             if (reg.IsMatch(webAdr))
  59.             {
  60.                 return "Browsing: " + webAdr + "!";
  61.             }
  62.             else
  63.             {
  64.                 return "Invalid URL!";
  65.             }
  66.             throw new NotImplementedException();
  67.         }
  68.     }
  69.  
  70.     interface ICallable
  71.     {
  72.         string CallOther(string number);
  73.     }
  74.  
  75.     interface IBrowsable
  76.     {
  77.         string BrowseInWeb(string webAdr);
  78.     }
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment