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.Runtime.CompilerServices;
- namespace AtTheZoo
- {
- class Program
- {
- static void Main(string[] args)
- {
- Animal monkey1 = new Animal("Monkey", "Male", "O-o-O-o!");
- Animal monkey2 = new Animal("Monkey", "Female", "O-o-O-o!!");
- Animal tiger1 = new Animal("Tiger", "Male", "Rrrr!");
- Animal tiger2 = new Animal("Tiger", "Female", "Rrrr!");
- Animal hippo1 = new Animal("Hippo", "Female", "bulp-bulp!");
- Animal hippo2 = new Animal("Hippo", "Female", "bulp-bulp!");
- Animal hippo3 = new Animal("Hippo", "Female", "bulp-bulp!");
- Animal parrot = new Animal("Parrot", "Male", "chik-chirik!");
- Enclosure cage1 = new Enclosure("Monkey Cage");
- cage1.AddAnimal(monkey1);
- cage1.AddAnimal(monkey2);
- Enclosure cage2 = new Enclosure("Tiger Cage");
- cage2.AddAnimal(tiger1);
- cage2.AddAnimal(tiger2);
- Enclosure cage3 = new Enclosure("Hippo's pool");
- cage3.AddAnimal(hippo1);
- cage3.AddAnimal(hippo2);
- cage3.AddAnimal(hippo3);
- Enclosure cage4 = new Enclosure("Parrot Cage");
- cage4.AddAnimal(parrot);
- Zoo zoo = new Zoo();
- zoo.AddEnclosure(cage1);
- zoo.AddEnclosure(cage2);
- zoo.AddEnclosure(cage3);
- zoo.AddEnclosure(cage4);
- while (true)
- {
- Console.Clear();
- Console.WriteLine("Welcome to the zoo!");
- Console.WriteLine("Выберите к какому вольеру подойти:");
- zoo.ShowEnclosures();
- int userInput = Convert.ToInt32(Console.ReadLine()) - 1;
- zoo.ShowInformation(userInput);
- Console.ReadKey();
- }
- }
- }
- class Zoo
- {
- private List<Enclosure> enclosures = new List<Enclosure>();
- public Zoo()
- {
- List<Enclosure> enclosures = new List<Enclosure>();
- }
- public void ShowInformation(int enclosureNumber)
- {
- Console.WriteLine($"Название: {enclosures[enclosureNumber].Name}");
- Console.WriteLine($"\nКоличество животных:{enclosures[enclosureNumber].ShowInformation("count")}");
- Console.WriteLine($"\nПол:{enclosures[enclosureNumber].ShowInformation("sex")}");
- Console.WriteLine($"\nВы слышите звук:{enclosures[enclosureNumber].ShowInformation("sound")}");
- }
- public void AddEnclosure(Enclosure cage)
- {
- enclosures.Add(cage);
- }
- public void ShowEnclosures()
- {
- int cageCount = 1;
- foreach (var item in enclosures)
- {
- Console.WriteLine($"[{cageCount}] - {item.Name}");
- cageCount++;
- }
- }
- }
- class Enclosure
- {
- public string Name { get; private set; }
- private List<Animal> _animals = new List<Animal>();
- public Enclosure(string name)
- {
- List<Animal> _animals = new List<Animal>();
- Name = name;
- }
- public string ShowInformation(string input)
- {
- if (input == "count")
- return _animals.Count.ToString();
- if (input == "sex")
- return _animals[0].Sex;
- if (input == "sound")
- return _animals[0].Sound;
- else
- return "Ошибка";
- }
- public void AddAnimal(Animal animal)
- {
- _animals.Add(animal);
- }
- }
- class Animal
- {
- public string Name { get; private set; }
- public string Sex { get; private set; }
- public string Sound { get; private set; }
- public Animal(string name, string sex, string sound)
- {
- Name = name;
- Sex = sex;
- Sound = sound;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement