Advertisement
OwlyOwl

Zoo

Jul 5th, 2020
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.30 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace AtTheZoo
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Console.WriteLine("Welcome to the zoo!");
  12.             List<Enclosure> enclosureList = new List<Enclosure>
  13.             {
  14.                 new Enclosure("Ostrich farm", 10, "female", "UA-UA-UA!"),
  15.                 new Enclosure("Monkey cage", 7, "male", "A-A-A!"),
  16.                 new Enclosure("Crocodile river", 15, "male", "Psst"),
  17.                 new Enclosure("Lions pride", 4, "female", "Arggh!")
  18.             };
  19.             Console.WriteLine("Выберите к какому вольеру подойти:");
  20.             foreach (var item in enclosureList)
  21.             {
  22.                 Console.WriteLine(item.Name);
  23.             }
  24.             int userInput = Convert.ToInt32(Console.ReadLine());
  25.             switch (userInput)
  26.             {
  27.                 case 1:
  28.                     enclosureList[userInput - 1].showInformation(userInput, enclosureList);
  29.                     break;
  30.                 case 2:
  31.                     enclosureList[userInput - 1].showInformation(userInput, enclosureList);
  32.                     break;
  33.                 case 3:
  34.                     enclosureList[userInput - 1].showInformation(userInput, enclosureList);
  35.                     break;
  36.                 case 4:
  37.                     enclosureList[userInput - 1].showInformation(userInput, enclosureList);
  38.                     break;
  39.             }
  40.         }
  41.     }
  42.  
  43.     class Enclosure
  44.     {
  45.         public string Name;
  46.         public int AnimalsAmount;
  47.         public string Sex;
  48.         public string Sound;
  49.  
  50.         public Enclosure(string name, int amount, string sex, string sound)
  51.         {
  52.             Name = name;
  53.             AnimalsAmount = amount;
  54.             Sex = sex;
  55.             Sound = sound;
  56.         }
  57.  
  58.         public void showInformation(int enclosureNumber, List<Enclosure> enclosures)
  59.         {
  60.             Console.WriteLine($"Название: {enclosures[enclosureNumber - 1].Name} \nКоличество животных: {enclosures[enclosureNumber - 1].AnimalsAmount} \nПол: {enclosures[enclosureNumber - 1].Sex} \nВы слышите звук: {enclosures[enclosureNumber - 1].Sound}");
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement