Advertisement
OwlyOwl

zoopark

Jul 11th, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.79 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.             List<Animal> monkeyList = new List<Animal>();
  22.             monkeyList.Add(monkey1);
  23.             monkeyList.Add(monkey2);
  24.             Enclosure cage1 = new Enclosure("Monkey Cage", monkeyList);
  25.             List<Animal> tigerList = new List<Animal>();
  26.             tigerList.Add(tiger1);
  27.             tigerList.Add(tiger2);
  28.             Enclosure cage2 = new Enclosure("Tiger Cage", tigerList);
  29.             List<Animal> hippoList = new List<Animal>();
  30.             hippoList.Add(hippo1);
  31.             hippoList.Add(hippo2);
  32.             Enclosure cage3 = new Enclosure("Hippo's pool", hippoList);
  33.             List<Animal> parrotList = new List<Animal>();
  34.             parrotList.Add(parrot);
  35.             Enclosure cage4 = new Enclosure("Parrot Cage", parrotList);
  36.  
  37.             List<Enclosure> enclosureList = new List<Enclosure>();
  38.             enclosureList.Add(cage1);
  39.             enclosureList.Add(cage2);
  40.             enclosureList.Add(cage3);
  41.             enclosureList.Add(cage4);
  42.  
  43.             while (true)
  44.             {
  45.                 Console.Clear();
  46.                 Console.WriteLine("Welcome to the zoo!");
  47.                 Console.WriteLine("Выберите к какому вольеру подойти:");
  48.                 int cageCount = 1;
  49.                 foreach (var item in enclosureList)
  50.                 {
  51.                     Console.WriteLine($"[{cageCount}] - {item.Name}");
  52.                     cageCount++;
  53.                 }
  54.                 int userInput = Convert.ToInt32(Console.ReadLine()) - 1;
  55.                 enclosureList[userInput].showInformation(userInput, enclosureList);
  56.                 Console.ReadKey();
  57.             }
  58.         }
  59.     }
  60.  
  61.     class Zoo
  62.     {
  63.         public List<Enclosure> EnclosureList { get; private set; }
  64.  
  65.         public Zoo(List<Enclosure> enclosureList)
  66.         {
  67.             EnclosureList = enclosureList;
  68.         }
  69.     }
  70.  
  71.     class Enclosure
  72.     {
  73.         public string Name { get; private set; }
  74.         public List<Animal> Animals { get; private set; }
  75.  
  76.         public Enclosure(string name, List<Animal> animals)
  77.         {
  78.             Animals = animals;
  79.             Name = name;
  80.         }
  81.  
  82.         public void showInformation(int enclosureNumber, List<Enclosure> enclosures)
  83.         {
  84.             Console.WriteLine($"Название: {enclosures[enclosureNumber].Name}");
  85.             Console.WriteLine($"\nКоличество животных:{enclosures[enclosureNumber].Animals.Count} ");
  86.             Console.WriteLine($"\nПол:{enclosures[enclosureNumber].Animals[0].Sex}");
  87.             Console.WriteLine($"\nВы слышите звук:{enclosures[enclosureNumber].Animals[0].Sound}");
  88.         }
  89.     }
  90.  
  91.     class Animal
  92.     {
  93.         public string Name { get; private set; }
  94.         public string Sex { get; private set; }
  95.         public string Sound { get; private set; }
  96.  
  97.         public Animal(string name, string sex, string sound)
  98.         {
  99.             Name = name;
  100.             Sex = sex;
  101.             Sound = sound;
  102.         }
  103.     }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement