Advertisement
OwlyOwl

Zooparkevich

Jul 19th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.14 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.CompilerServices;
  5.  
  6. namespace AtTheZoo
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Animal monkey1 = new Animal("Monkey", "Male", "O-o-O-o!");
  13.             Animal monkey2 = new Animal("Monkey", "Female", "O-o-O-o!!");
  14.             Animal tiger1 = new Animal("Tiger", "Male", "Rrrr!");
  15.             Animal tiger2 = new Animal("Tiger", "Female", "Rrrr!");
  16.             Animal hippo1 = new Animal("Hippo", "Female", "bulp-bulp!");
  17.             Animal hippo2 = new Animal("Hippo", "Female", "bulp-bulp!");
  18.             Animal hippo3 = new Animal("Hippo", "Female", "bulp-bulp!");
  19.             Animal parrot = new Animal("Parrot", "Male", "chik-chirik!");
  20.  
  21.             Enclosure cage1 = new Enclosure("Monkey Cage");
  22.             cage1.AddAnimal(monkey1);
  23.             cage1.AddAnimal(monkey2);
  24.             Enclosure cage2 = new Enclosure("Tiger Cage");
  25.             cage2.AddAnimal(tiger1);
  26.             cage2.AddAnimal(tiger2);
  27.             Enclosure cage3 = new Enclosure("Hippo's pool");
  28.             cage3.AddAnimal(hippo1);
  29.             cage3.AddAnimal(hippo2);
  30.             cage3.AddAnimal(hippo3);
  31.             Enclosure cage4 = new Enclosure("Parrot Cage");
  32.             cage4.AddAnimal(parrot);
  33.             Zoo zoo = new Zoo();
  34.             zoo.AddEnclosure(cage1);
  35.             zoo.AddEnclosure(cage2);
  36.             zoo.AddEnclosure(cage3);
  37.             zoo.AddEnclosure(cage4);
  38.  
  39.             while (true)
  40.             {
  41.                 Console.Clear();
  42.                 Console.WriteLine("Welcome to the zoo!");
  43.                 Console.WriteLine("Выберите к какому вольеру подойти:");
  44.                 zoo.ShowEnclosures();
  45.                 int userInput = Convert.ToInt32(Console.ReadLine()) - 1;
  46.                 zoo.ShowInformation(userInput);
  47.                 Console.ReadKey();
  48.             }
  49.         }
  50.     }
  51.  
  52.     class Zoo
  53.     {
  54.         private List<Enclosure> enclosures = new List<Enclosure>();
  55.  
  56.         public Zoo()
  57.         {
  58.             List<Enclosure> enclosures = new List<Enclosure>();
  59.         }
  60.  
  61.         public void ShowInformation(int enclosureNumber)
  62.         {
  63.             Console.WriteLine($"Название: {enclosures[enclosureNumber].Name}");
  64.             Console.WriteLine($"\nКоличество животных:{enclosures[enclosureNumber].ShowInformation("count")}");
  65.             Console.WriteLine($"\nПол:{enclosures[enclosureNumber].ShowInformation("sex")}");
  66.             Console.WriteLine($"\nВы слышите звук:{enclosures[enclosureNumber].ShowInformation("sound")}");
  67.         }
  68.  
  69.         public void AddEnclosure(Enclosure cage)
  70.         {
  71.             enclosures.Add(cage);
  72.         }
  73.  
  74.         public void ShowEnclosures()
  75.         {
  76.             int cageCount = 1;
  77.             foreach (var item in enclosures)
  78.             {
  79.                 Console.WriteLine($"[{cageCount}] - {item.Name}");
  80.                 cageCount++;
  81.             }
  82.         }
  83.     }
  84.  
  85.     class Enclosure
  86.     {
  87.         public string Name { get; private set; }
  88.         private List<Animal> _animals = new List<Animal>();
  89.  
  90.         public Enclosure(string name)
  91.         {
  92.             List<Animal> _animals = new List<Animal>();
  93.             Name = name;
  94.         }
  95.  
  96.         public string ShowInformation(string input)
  97.         {
  98.             if (input == "count")
  99.                 return _animals.Count.ToString();
  100.  
  101.             if (input == "sex")
  102.                 return _animals[0].Sex;
  103.  
  104.             if (input == "sound")
  105.                 return _animals[0].Sound;
  106.  
  107.             else
  108.                 return "Ошибка";
  109.         }
  110.  
  111.         public void AddAnimal(Animal animal)
  112.         {
  113.             _animals.Add(animal);
  114.         }
  115.     }
  116.  
  117.     class Animal
  118.     {
  119.         public string Name { get; private set; }
  120.         public string Sex { get; private set; }
  121.         public string Sound { get; private set; }
  122.  
  123.         public Animal(string name, string sex, string sound)
  124.         {
  125.             Name = name;
  126.             Sex = sex;
  127.             Sound = sound;
  128.         }
  129.     }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement