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 Program
- {
- static void Main(string[] args)
- {
- Zoo zoo = new Zoo();
- zoo.Work();
- }
- }
- class Zoo
- {
- private List<Cage> _cages;
- public Zoo()
- {
- _cages = new List<Cage>();
- Create();
- }
- public void Work()
- {
- ConsoleKeyInfo consoleKey;
- do
- {
- Console.Clear();
- ShowAllCages();
- ShowCage();
- consoleKey = Console.ReadKey();
- }
- while(consoleKey.Key != ConsoleKey.Escape);
- }
- private void ShowCage()
- {
- int cageIndex;
- Console.WriteLine("\nChoose cage: ");
- cageIndex = GetNumber() - 1;
- if (cageIndex >= 0 && cageIndex < _cages.Count)
- {
- _cages[cageIndex].ShowInfo();
- }
- else
- {
- Console.WriteLine("Wrong action");
- }
- }
- private void ShowAllCages()
- {
- for (int i = 1; i <= _cages.Count; i++)
- {
- Console.WriteLine($"{i}.{_cages[i - 1].Name} cage");
- }
- }
- private void Create()
- {
- _cages.Add(new Cage(3, new Animal("Wolfs", "A-ooooooo", "male")));
- _cages.Add(new Cage(6, new Animal("Monkey", "Ooo-a-a-a-ooo-a", "male, female")));
- _cages.Add(new Cage(2, new Animal("Bear", "Aghrrr", "male")));
- _cages.Add(new Cage(9, new Animal("Snake", "Sssss-ssss", "male, female")));
- }
- private int GetNumber()
- {
- int number;
- string userInput;
- do
- {
- userInput = Console.ReadLine();
- }
- while (int.TryParse(userInput, out number) == false);
- return number;
- }
- }
- class Cage
- {
- private Animal _animal;
- public int AnimalsQuantity { get; private set; }
- public string Name => _animal.Name;
- public Cage(int quantity, Animal animal)
- {
- AnimalsQuantity = quantity;
- _animal = animal;
- }
- public void ShowInfo()
- {
- Console.WriteLine($"Cage of {_animal.Name} | Animals gender: {_animal.Sex} | Animals quantity: {AnimalsQuantity} | Animals sound: {_animal.Sound}");
- }
- }
- class Animal
- {
- public string Name { get; private set; }
- public string Sound { get; private set; }
- public string Sex { get; private set; }
- public Animal(string name, string sound, string sex)
- {
- Name = name;
- Sound = sound;
- Sex = sex;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement