kisame1313

Untitled

Jul 22nd, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.51 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5.     static void Main ( string [] args )
  6.     {
  7.         House house = new House ( ConsoleColor.DarkGreen, "ul Kukueva", 2 );
  8.         house.FillHouse ( new Tenant ( "Sergei", 20 ) );
  9.        
  10.         house.FillHouse (
  11.             new Tenant ( "Roma", 20 ),
  12.             new Tenant ( "Wasya", 25 )
  13.             );
  14.  
  15.         for ( int i = 0 ; i < house.Tenants.Length ; i++ )
  16.         {
  17.             Console.WriteLine ( house.Tenants [i].Name );
  18.         }
  19.  
  20.     }
  21.  
  22. }
  23.  
  24. class House
  25. {
  26.     ConsoleColor HouseColor;
  27.     string Adress;
  28.     int MaxTenants;
  29.     public Tenant [] Tenants;
  30.     public bool IsFull = false;
  31.  
  32.     public House ( ConsoleColor col, string adr, int max )
  33.     {
  34.         HouseColor = col;
  35.         Adress = adr;
  36.         MaxTenants = max;
  37.         Tenants = new Tenant [max];
  38.     }
  39.  
  40.     public void ShowAdress ()
  41.     {
  42.         ConsoleColor defaultColor = Console.ForegroundColor;
  43.         Console.ForegroundColor = HouseColor;
  44.         Console.WriteLine ( Adress );
  45.         Console.ForegroundColor = defaultColor;
  46.     }
  47.  
  48.     public static bool FindTenant ( Tenant ten )
  49.     {
  50.         return ten != null;
  51.     }
  52.  
  53.     Predicate<Tenant> findTenant = FindTenant;
  54.  
  55.     public void FillHouse ( params Tenant [] tenant )
  56.     {
  57.  
  58.         int lastTenantID = Array.FindLastIndex ( Tenants, findTenant );
  59.         lastTenantID++;
  60.         for ( int i = 0 ; i < tenant.Length ; i++ )
  61.         {
  62.             if ( lastTenantID < Tenants.Length - 1 )
  63.             {
  64.                 Tenants [lastTenantID] = tenant [i];
  65.                 lastTenantID++;
  66.             }
  67.             else
  68.                 break;
  69.         }
  70.  
  71.     }
  72. }
  73.  
  74. class Tenant
  75. {
  76.     public string Name;
  77.     byte Age;
  78.  
  79.     public Tenant ( string name, byte age )
  80.     {
  81.         Name = name;
  82.         Age = age;
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment