Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.39 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Colos2
  7. {
  8.     class Osoba
  9.     {
  10.         public string Imie { get; set; }
  11.         public string Nazwisko { get; set; }
  12.  
  13.         public Osoba(string Imie, string Nazwisko)
  14.         {
  15.             this.Imie = Imie;
  16.             this.Nazwisko = Nazwisko;
  17.         }
  18.     }
  19.  
  20.     class Pokoj
  21.     {
  22.         public int Numer { get; set; }
  23.         public int LiczbaOsob { get; set; }
  24.         public bool Rezerwacja { get; set; }
  25.         public Osoba Gosc { get; set; }
  26.  
  27.         public Pokoj()
  28.         {
  29.             Gosc = new Osoba(null, null);
  30.         }
  31.  
  32.         public Pokoj(int Numer, int LiczbaOsob)
  33.         {
  34.             this.Numer = Numer;
  35.             this.LiczbaOsob = LiczbaOsob;
  36.             Rezerwacja = false;
  37.             Gosc = new Osoba(null, null);
  38.         }
  39.         public string CzyZarezerwowany()
  40.         {
  41.             if (Rezerwacja == true)
  42.                 return string.Format("zarezerwowany");
  43.             else
  44.                 return string.Format("wolny");
  45.         }
  46.  
  47.         public void Rezerwuj(string Imie, string Nazwisko)
  48.         {
  49.             Gosc = new Osoba(Imie, Nazwisko);
  50.             Rezerwacja = true;
  51.         }
  52.  
  53.         public string InfoPokoj()
  54.         {
  55.             if (Rezerwacja == true)
  56.                 return string.Format("Pokoj numer {0} jest {1} osobowy, jest {2} dla goscia Oskar Niewadzisz.", this.Numer, this.LiczbaOsob, this.CzyZarezerwowany());
  57.             else
  58.                 return string.Format("Pokoj numer {0} jest {1} osobowy, jest {2}.", this.Numer, this.LiczbaOsob, this.CzyZarezerwowany());
  59.         }
  60.  
  61.         public override string ToString()
  62.         {
  63.             return string.Format("Pokoj o numerze: {0}. Jest {1}", this.Numer, this.CzyZarezerwowany());
  64.         }
  65.     }
  66.  
  67.     class Hotel
  68.     {
  69.         public List<Pokoj> Pokoje { get; set; }
  70.  
  71.         public Hotel()
  72.         {
  73.             Pokoje = new List<Pokoj>();
  74.         }
  75.  
  76.         public Hotel(int Numer, int LiczbaOsob)
  77.         {
  78.             Pokoje = new List<Pokoj>();
  79.             Pokoj pokoj = new Pokoj(Numer, LiczbaOsob);
  80.             Pokoje.Add(pokoj);
  81.         }
  82.  
  83.         public void DodajPokoj(int Numer, int LiczbaOsob)
  84.         {
  85.             Pokoj pokoj = new Pokoj(Numer, LiczbaOsob);
  86.                 Pokoje.Add(pokoj);
  87.         }
  88.  
  89.         public void RezerwujPokoj(int N, string Imie, string Nazwisko)
  90.         {
  91.             Pokoje.Find(k => k.Numer == N).Rezerwuj(Imie, Nazwisko);
  92.         }
  93.  
  94.         public void WyswietlPokoje()
  95.         {
  96.             for (int i = 0; i < Pokoje.Count; i++)
  97.             {
  98.                 Console.WriteLine(Pokoje[i]);
  99.             }
  100.         }
  101.     }
  102.  
  103.     class Program
  104.     {
  105.         static void Main(string[] args)
  106.         {
  107.             Pokoj pokoj = new Pokoj(3, 1);
  108.             Console.WriteLine(pokoj.InfoPokoj());
  109.  
  110.             pokoj.Rezerwuj("Oskar", "Niewadzisz");
  111.             Console.WriteLine(pokoj.InfoPokoj());
  112.  
  113.             Console.WriteLine("\n-----------------------------------------------------");
  114.  
  115.             Hotel hotel = new Hotel();
  116.             hotel.DodajPokoj(1, 1);
  117.             hotel.DodajPokoj(2, 2);
  118.             hotel.DodajPokoj(3, 3);
  119.  
  120.             hotel.RezerwujPokoj(3, "Oskar", "Niewadzisz");
  121.  
  122.             hotel.WyswietlPokoje();
  123.  
  124.             Console.ReadKey();
  125.         }
  126.     }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement