Advertisement
OwlyOwl

zOooooo

Jul 14th, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.56 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> enclosures = new List<Enclosure>();
  38.             enclosures.Add(cage1);
  39.             enclosures.Add(cage2);
  40.             enclosures.Add(cage3);
  41.             enclosures.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 enclosures)
  50.                 {
  51.                     Console.WriteLine($"[{cageCount}] - {item.Name}");
  52.                     cageCount++;
  53.                 }
  54.                 int userInput = Convert.ToInt32(Console.ReadLine()) - 1;
  55.                 enclosures[userInput].showInformation(userInput, enclosures);
  56.                 Console.ReadKey();
  57.             }
  58.         }
  59.     }
  60.  
  61.     class Enclosure
  62.     {
  63.         public string Name { get; private set; }
  64.         private List<Animal> _animals = new List<Animal>();
  65.  
  66.         public Enclosure(string name, List<Animal> animals)
  67.         {
  68.             _animals = animals;
  69.             Name = name;
  70.         }
  71.  
  72.         public void showInformation(int enclosureNumber, List<Enclosure> enclosures)
  73.         {
  74.             Console.WriteLine($"Название: {enclosures[enclosureNumber].Name}");
  75.             Console.WriteLine($"\nКоличество животных:{enclosures[enclosureNumber]._animals.Count} ");
  76.             Console.WriteLine($"\nПол:{enclosures[enclosureNumber]._animals[0].Sex}");
  77.             Console.WriteLine($"\nВы слышите звук:{enclosures[enclosureNumber]._animals[0].Sound}");
  78.         }
  79.     }
  80.  
  81.     class Animal
  82.     {
  83.         public string Name { get; private set; }
  84.         public string Sex { get; private set; }
  85.         public string Sound { get; private set; }
  86.  
  87.         public Animal(string name, string sex, string sound)
  88.         {
  89.             Name = name;
  90.             Sex = sex;
  91.             Sound = sound;
  92.         }
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement