Facebook
From Eratic Madrill, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 133
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5.  
  6. namespace ConsoleApp20
  7. {
  8.    
  9.     class Program
  10.     {
  11.         public static void Main(string[] args)
  12.         {
  13.            
  14.             List<Nocleg> noclegsList = new List<Nocleg>();
  15.             noclegsList.Add(new Pensjonat("1", 10, 1300, "drogo"));
  16.             noclegsList.Add(new Hotel("2", 10, 2000, 5));
  17.             noclegsList.Add(new Motel("3", 10, 800, false, true));
  18.             Console.WriteLine("Podaj nazwe noclegu : ");
  19.             string nazwa = Convert.ToString(Console.ReadLine());
  20.             for (int i = 0; i < noclegsList.Count; i++)
  21.             {
  22.                 if (nazwa == noclegsList[i].Nazwa)
  23.                 {
  24.                     Console.WriteLine("Nazwa : " + noclegsList[i].Nazwa + "\nIloscMiejsc: " + noclegsList[i].IloscMiejsc + "\nCena: " + noclegsList[i].Cena);
  25.                 }
  26.             }
  27.             Console.ReadKey();
  28.            
  29.         }
  30.     }
  31.  
  32.     abstract class Nocleg
  33.     {
  34.         public Nocleg()
  35.         {
  36.             this.Nazwa = "";
  37.             this.IloscMiejsc = 0;
  38.             this.Cena = 0;
  39.         }
  40.         public Nocleg(string nazwa, int iloscmiejsc, int cena)
  41.         {
  42.             this.Nazwa = nazwa;
  43.             this.IloscMiejsc = iloscmiejsc;
  44.             this.Cena = cena;
  45.         }
  46.         public string Nazwa
  47.         {
  48.             get;
  49.             protected set;
  50.         }
  51.         public int IloscMiejsc
  52.         {
  53.             get;
  54.             protected set;
  55.         }
  56.         public int Cena
  57.         {
  58.             get;
  59.             protected set;
  60.         }
  61.     }
  62.  
  63.     class Hotel : Nocleg
  64.     {
  65.         public Hotel() : base()
  66.         {
  67.             this.Gwiazdki = 0;
  68.         }
  69.         public Hotel(string nazwa, int iloscmiejsc, int cena, int gwiazdki) : base(nazwa, iloscmiejsc, cena)
  70.         {
  71.             this.Gwiazdki = gwiazdki;
  72.         }
  73.         public int Gwiazdki
  74.         {
  75.             get;
  76.             protected set;
  77.         }
  78.     }
  79.     class Pensjonat : Nocleg
  80.     {
  81.         public Pensjonat()
  82.         {
  83.             this.OpisTurystyczny = "";
  84.         }
  85.         public Pensjonat(string nazwa, int iloscmiejsc, int cena, string opisturystyczny) : base(nazwa, iloscmiejsc, cena)
  86.         {
  87.             this.OpisTurystyczny = opisturystyczny;
  88.         }
  89.         public string OpisTurystyczny
  90.         {
  91.             get;
  92.             protected set;
  93.         }
  94.     }
  95.     class Motel : Nocleg
  96.     {
  97.         public Motel() : base()
  98.         {
  99.             this.WspolnaLazienka = false;
  100.             this.Sniadanie = false;
  101.         }
  102.         public Motel(string nazwa, int iloscmiejsc, int cena, bool sniadanie, bool wspolnalazienka) : base(nazwa, iloscmiejsc, cena)
  103.         {
  104.             this.Sniadanie = sniadanie;
  105.             this.WspolnaLazienka = wspolnalazienka;
  106.         }
  107.         public bool WspolnaLazienka
  108.         {
  109.             get;
  110.             protected set;
  111.         }
  112.         public bool Sniadanie
  113.         {
  114.             get;
  115.             protected set;
  116.         }
  117.     }
  118.  
  119. }
  120.  
  121.