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 ООП
- {
- class Program
- {
- static void Main(string[] args)
- {
- Zoo zoo = new Zoo();
- zoo.Work();
- }
- }
- class Zoo
- {
- private List<Aviary> _aviaries = new List<Aviary>();
- public Zoo()
- {
- _aviaries = new List<Aviary>();
- }
- public void Work()
- {
- bool isOpen = true;
- AddAnimals();
- while (isOpen)
- {
- Console.Clear();
- ShowAviaries();
- Console.Write("\nВведите номер вальера, чтобы к нему подойти:");
- string userInput = Console.ReadLine();
- bool correctImput = int.TryParse(userInput, out int index);
- --index;
- if (correctImput && index >= 0 && index < _aviaries.Count())
- {
- Console.Clear();
- ShowAviary(index);
- Console.ReadKey();
- }
- }
- }
- private void ShowAviary(int index)
- {
- _aviaries[index].ShowInfo();
- }
- private void ShowAviaries()
- {
- foreach (var aviary in _aviaries)
- {
- Console.WriteLine($"Вальер №{_aviaries.IndexOf(aviary) + 1}, в котором находятся {aviary.Type}");
- }
- }
- private void AddAnimals()
- {
- _aviaries.Add(new Aviary("Львы", new Animal[] { new("Лев", "*звуки льва*", true), new("Львица", "*звуки львицы*", false)}));
- _aviaries.Add(new Aviary("Лоси", new Animal[] { new("Лось", "*звуки лося*", true), new("Лосиха", "*звуки лосихи*", false) }));
- _aviaries.Add(new Aviary("Утки", new Animal[] { new("Селезень", "*звуки селезня*", true), new("Кряква", "*звуки кряквы*", false) }));
- _aviaries.Add(new Aviary("Попугаи", new Animal[] { new("Попугай", "*звуки попугая*", true), new("Попугай", "*звуки попугая*", false) }));
- _aviaries.Add(new Aviary("Крокодилы", new Animal[] { new("Крокодил", "*звуки крокодила*", true), new("Крокодил", "*звуки крокодила*", false) }));
- }
- }
- class Aviary
- {
- private List<Animal> _animals = new List<Animal>();
- public string Type { get; private set; }
- public Aviary(string type, Animal[] animals)
- {
- Type = type;
- _animals.AddRange(animals);
- }
- public void ShowInfo()
- {
- Console.WriteLine($"Вальер в котором {Type}. Список животных: \n");
- foreach (var animal in _animals)
- {
- animal.ShowInfo();
- }
- }
- }
- class Animal
- {
- private string _name;
- private string _gender;
- private string _voice;
- public Animal(string name, string voice, bool beMale)
- {
- _name = name;
- if (beMale)
- _gender = "♂";
- else
- _gender = "♀";
- _voice = voice;
- }
- public void ShowInfo()
- {
- Console.WriteLine($"Вид: {_name} | Пол: {_gender} | Издаёт звук: {_voice}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment