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 zoo
- {
- class main
- {
- static void Main(string[] args)
- {
- Zoo zoo = new Zoo();
- zoo.RunMenu();
- }
- }
- class Zoo
- {
- private List<Aviary> _aviaries;
- private List<Animal> _animals;
- public Zoo()
- {
- _aviaries = new List<Aviary>();
- Animal bear = new Animal("Медведь", 'М', "Рык");
- Animal wolf = new Animal("Волк", 'М', "Лай");
- Animal tiger = new Animal("Тигр", 'Ж', "Мяу");
- _animals = new List<Animal>()
- {
- bear,
- wolf,
- tiger
- };
- }
- public void RunMenu()
- {
- bool isRun = true;
- while(isRun)
- {
- Console.WriteLine("[1] - список вальеров с животными\n" +
- "[2] - список животных Зоопарка\n" +
- "[3] - создать вальер\n" +
- "[4] - добавить животное в вальер\n" +
- "[5] - убрать животное из вальера\n" +
- "[6] - добавить животного в зоопарк\n" +
- "[7] - удалить животного из зоопарка\n" +
- "[8] - выход");
- Console.Write("Ввод: ");
- switch (Console.ReadLine())
- {
- case "1":
- ShowAviaries();
- break;
- case "2":
- ShowAnimals();
- break;
- case "3":
- AddAviary();
- break;
- case "4":
- AddAviaryAnimal();
- break;
- case "5":
- RemoveAviaryAnimal();
- break;
- case "6":
- AddAnimal();
- break;
- case "7":
- RemoveAnimal();
- break;
- case "8":
- isRun = false;
- break;
- default:
- Console.WriteLine("Ошибка!");
- break;
- }
- Console.ReadKey();
- Console.Clear();
- }
- }
- private void ShowAviaries()
- {
- if(CheckAviaryCount() == false)
- {
- return;
- }
- foreach (var aviary in _aviaries)
- {
- Console.WriteLine($"{aviary.Number}:");
- aviary.ShowAnimals();
- }
- }
- private void ShowAnimals()
- {
- if (CheckAnimalsCount() == false)
- {
- return;
- }
- foreach (var animal in _animals)
- {
- Console.WriteLine($"{animal.Name}; Пол - {animal.Sex}; Звук - {animal.Sound}");
- }
- }
- private void AddAviary()
- {
- Aviary aviary = new Aviary(_aviaries.Count + 1);
- _aviaries.Add(aviary);
- }
- private void AddAviaryAnimal()
- {
- Console.WriteLine("Укажите номер вальера: ");
- if (IsInputVerified(out int avaryNumber, _aviaries.Count()))
- {
- Console.WriteLine("Укажите номер животного: ");
- if (IsInputVerified(out int animalNumber, _animals.Count()))
- {
- _aviaries[avaryNumber].AddAnimal(_animals[animalNumber]);
- }
- }
- }
- private void RemoveAviaryAnimal()
- {
- if (CheckAnimalsCount() == false)
- {
- return;
- }
- Console.WriteLine("Укажите номер вальера: ");
- if (IsInputVerified(out int avaryNumber, _aviaries.Count()))
- {
- if (_aviaries[avaryNumber].DoAnimalsExist() == false)
- {
- Console.WriteLine("В вальере нет животных!");
- return;
- }
- Console.WriteLine("Укажите номер животного: ");
- if (IsInputVerified(out int animalNumber, _animals.Count()))
- {
- _aviaries[avaryNumber].RemoveAnimal(_animals[animalNumber]);
- }
- }
- }
- private void AddAnimal()
- {
- Console.Write("Введите имя: ");
- string name = Console.ReadLine();
- Console.Write("Введите пол. [М] - Самец, [Ж] - Самка: ");
- char sex = Convert.ToChar(Console.ReadLine());
- Console.Write("Какой звук издает животное: ");
- string sound = Console.ReadLine();
- Animal animal = new Animal(name, sex, sound);
- _animals.Add(animal);
- }
- private void RemoveAnimal()
- {
- if(CheckAnimalsCount() == false)
- {
- return;
- }
- Console.WriteLine("Номер животного, которого нужно вычеркнуть из зоопарка: ");
- if (IsInputVerified(out int number, _animals.Count))
- {
- _animals.RemoveAt(number);
- }
- }
- private bool IsInputVerified(out int userInput, int count)
- {
- if (int.TryParse(Console.ReadLine(), out userInput) && userInput <= count && userInput > 0)
- {
- --userInput;
- return true;
- }
- Console.WriteLine("Ошибка, такого номера нет!");
- return false;
- }
- private bool CheckAnimalsCount()
- {
- if(_animals.Count == 0)
- {
- Console.WriteLine("В зоопарке нет животных!");
- return false;
- }
- return true;
- }
- private bool CheckAviaryCount()
- {
- if (_aviaries.Count == 0)
- {
- Console.WriteLine("Вальеры не созданы!");
- return false;
- }
- return true;
- }
- }
- class Aviary
- {
- private List<Animal> _animals;
- public int Number { get; private set; }
- public Aviary(int aviaryNumber)
- {
- _animals = new List<Animal>();
- Number = aviaryNumber;
- }
- public void ShowAnimals()
- {
- if(_animals.Count == 0)
- {
- Console.WriteLine("В вальере нет животных!");
- return;
- }
- Console.WriteLine("Список животных: ");
- foreach (var animal in _animals)
- {
- Console.WriteLine($"{animal.Name}; Пол - {animal.Sex}; Звук - {animal.Sound}");
- }
- }
- public void AddAnimal(Animal animal)
- {
- _animals.Add(animal);
- }
- public void RemoveAnimal(Animal animal)
- {
- _animals.Remove(animal);
- }
- public bool DoAnimalsExist()
- {
- return _animals.Count > 0;
- }
- }
- class Animal
- {
- public string Male = "Самец";
- public string Female = "Самка";
- public string Name { get; private set; }
- public string Sound { get; private set; }
- public string Sex { get; private set; }
- public Animal(string name, char sex, string sound)
- {
- Name = name;
- Sound = sound;
- if(sex == 'Ж')
- {
- Sex = Female;
- }
- else
- {
- Sex = Male;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement