Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace Homework10
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<Aviary> aviaries = new List<Aviary>
- {
- new Aviary(new List<Inhabitant>
- {
- new Inhabitant("lion", "male", "meow"),
- new Inhabitant("lion", "female" , "meow"),
- }),
- new Aviary(new List<Inhabitant>
- {
- new Inhabitant("elephant", "male", "trumpet"),
- new Inhabitant("elephant", "female" , "trumpet"),
- }),
- new Aviary(new List<Inhabitant>
- {
- new Inhabitant("bird", "male", "chirp"),
- new Inhabitant("bird", "female"),
- }),
- new Aviary(new List<Inhabitant>
- {
- new Inhabitant("wolf", "male", "bark"),
- new Inhabitant("wolf", "female" , "bark"),
- }),
- new Aviary(),
- new Aviary(),
- new Aviary(),
- new Aviary(),
- };
- bool isActive = true;
- while (isActive == true)
- {
- ChooseAviary(aviaries);
- Console.ReadKey();
- Console.Clear();
- }
- }
- static void ChooseAviary(List<Aviary> aviaries)
- {
- for (int i = 0; i < aviaries.Count; i++)
- {
- Console.Write(i + " ");
- aviaries[i].Glance();
- }
- Console.Write("Choose:");
- if (int.TryParse(Console.ReadLine(), out int aviaryNumber) == true)
- {
- if (aviaryNumber >= 0 && aviaryNumber < aviaries.Count)
- {
- Console.Clear();
- aviaries[aviaryNumber].ShowInfo();
- }
- else
- {
- Console.WriteLine("Неверное число!");
- }
- }
- else
- {
- Console.WriteLine("Это не число!");
- }
- }
- }
- class Aviary
- {
- private List<Inhabitant> _inhabitants;
- private static Random _random;
- public int Capacity { get; private set; }
- static Aviary()
- {
- _random = new Random();
- }
- public Aviary(List<Inhabitant> inhabitants)
- {
- _inhabitants = inhabitants;
- Capacity = inhabitants.Count;
- }
- public Aviary()
- {
- Capacity = _random.Next(5, 11);
- _inhabitants = new List<Inhabitant> { };
- for (int i = 0; i < Capacity; i++)
- {
- _inhabitants.Add(new Inhabitant());
- }
- }
- public void ShowInfo()
- {
- Console.WriteLine($"--{Capacity} inhabitant(s)--");
- foreach (var inhabitant in _inhabitants)
- {
- inhabitant.Introduce();
- }
- }
- public void Glance()
- {
- Console.WriteLine($"Вольер с {Capacity} животными");
- }
- }
- class Inhabitant
- {
- private List<string> _types = new List<string> { "wolf", "bird", "elephant", "lion" };
- private List<string> _genders = new List<string> { "male", "female" };
- private List<string> _sounds = new List<string> { "bark", "chirp", "trumpet", "meow"};
- private static Random _random;
- public string Type { get; private set; }
- public string Gender { get; private set; }
- public string Sound { get; private set; }
- static Inhabitant()
- {
- _random = new Random();
- }
- public Inhabitant(string type, string gender, string sound = null)
- {
- Type = type;
- Gender = gender;
- Sound = sound;
- }
- public Inhabitant()
- {
- int inhabitantNumber = _random.Next(0, _types.Count);
- Type = _types[inhabitantNumber];
- Gender = _genders[_random.Next(0, 2)];
- Sound = _sounds[inhabitantNumber];
- }
- public void Introduce()
- {
- if (Sound == null)
- Sound = "no sound";
- Console.WriteLine($"Type: {Type}\nGender: {Gender}\nSound: {Sound}");
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment