Advertisement
alexey3017

Untitled

Mar 28th, 2020
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.55 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace learn1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             bool isOpen = true;
  14.             Enclosure[] enclosures = { new Animal("Это вольер с Кошками", 10, "женский","Мяу-Мяу-Мяу"), new Animal("Это вольер с собаками", 5, "мужской","Гав-Гав-Гав"), new Animal("В данном пвольере живут утки", 2, "мужской","Кря-Кря-Кря"), new Animal("Тут живет одна волчица", 1, "женский","Аууу-Аууу-Аууу")};
  15.             int userInput;
  16.             while (isOpen)
  17.             {
  18.                 Console.WriteLine("К какому вальеру подойти хотите?");
  19.                 Console.WriteLine("1 - первый.\n2 - второй.\n3 - третий\n4 - четвертый\n0 - выход из программы");
  20.                 userInput = Convert.ToInt32(Console.ReadLine()) - 1;
  21.                 if (userInput <= 3)
  22.                 {
  23.                     enclosures[userInput].ShowInfo();
  24.                     enclosures[userInput].MakeSound();
  25.                 }
  26.                 else if (userInput == 0)
  27.                 {
  28.                     Console.WriteLine("До свидания");
  29.                     isOpen = false;
  30.                 }
  31.                 else
  32.                 {
  33.                     Console.WriteLine("Такого вольера не существует");
  34.                 }
  35.             }
  36.         }
  37.     }
  38.  
  39.     class Enclosure
  40.     {
  41.         private string _information;
  42.         private int _animals;
  43.         private string _floor;
  44.         private string _sound;
  45.         public Enclosure(string information, int animals, string floor,string sound)
  46.         {
  47.             _information = information; ;
  48.             _animals = animals;
  49.             _floor = floor;
  50.             _sound = sound;
  51.         }
  52.  
  53.         public void ShowInfo()
  54.         {
  55.             Console.WriteLine($"{_information}, В нем находится {_animals} особей, пол: {_floor}. ");
  56.  
  57.         }
  58.  
  59.         public void MakeSound()
  60.         {
  61.             Console.WriteLine($"Животные издают звук: {_sound}");
  62.         }
  63.     }
  64.     class Animal : Enclosure
  65.     {
  66.         public Animal(string information, int animals, string floor,string sound) : base(information, animals, floor,sound)
  67.         {
  68.         }
  69.        
  70.  
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement