Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace learn1
- {
- class Program
- {
- static void Main(string[] args)
- {
- bool isOpen = true;
- Enclosure[] enclosures = { new Animal("Это вольер с Кошками", 10, "женский","Мяу-Мяу-Мяу"), new Animal("Это вольер с собаками", 5, "мужской","Гав-Гав-Гав"), new Animal("В данном пвольере живут утки", 2, "мужской","Кря-Кря-Кря"), new Animal("Тут живет одна волчица", 1, "женский","Аууу-Аууу-Аууу")};
- int userInput;
- while (isOpen)
- {
- Console.WriteLine("К какому вальеру подойти хотите?");
- Console.WriteLine("1 - первый.\n2 - второй.\n3 - третий\n4 - четвертый\n0 - выход из программы");
- userInput = Convert.ToInt32(Console.ReadLine()) - 1;
- if (userInput <= 3)
- {
- enclosures[userInput].ShowInfo();
- enclosures[userInput].MakeSound();
- }
- else if (userInput == 0)
- {
- Console.WriteLine("До свидания");
- isOpen = false;
- }
- else
- {
- Console.WriteLine("Такого вольера не существует");
- }
- }
- }
- }
- class Enclosure
- {
- private string _information;
- private int _animals;
- private string _floor;
- private string _sound;
- public Enclosure(string information, int animals, string floor,string sound)
- {
- _information = information; ;
- _animals = animals;
- _floor = floor;
- _sound = sound;
- }
- public void ShowInfo()
- {
- Console.WriteLine($"{_information}, В нем находится {_animals} особей, пол: {_floor}. ");
- }
- public void MakeSound()
- {
- Console.WriteLine($"Животные издают звук: {_sound}");
- }
- }
- class Animal : Enclosure
- {
- public Animal(string information, int animals, string floor,string sound) : base(information, animals, floor,sound)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement