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 aquarium
- {
- class Program
- {
- static void Main(string[] args)
- {
- Aquarium aquarium = new Aquarium();
- aquarium.RunMenu();
- }
- }
- class Aquarium
- {
- private List<Fish> _fishes;
- private int _maxSize = 0;
- public Aquarium()
- {
- _fishes = new List<Fish>();
- }
- public void RunMenu()
- {
- bool isRun = true;
- while(isRun)
- {
- Console.WriteLine("[1] - добавить рыбу\n" +
- "[2] - убрать рыбу\n" +
- "[3] - увеличить размер аквариума\n" +
- "[4] - выход\n");
- ShowFishes();
- Console.Write("\nВвод: ");
- switch (Console.ReadLine())
- {
- case "1":
- AddFish();
- break;
- case "2":
- DeleteFish();
- break;
- case "3":
- IncreaseMaxSize();
- break;
- case "4":
- isRun = false;
- break;
- default:
- Console.WriteLine("Ожидаем...");
- break;
- }
- Console.ReadKey(true);
- Console.Clear();
- IncreaseAgeFishes();
- }
- }
- private void IncreaseMaxSize()
- {
- Console.Write("Задайте размер аквариума: ");
- if (int.TryParse(Console.ReadLine(), out int number) && number > _fishes.Count)
- {
- _maxSize = number;
- }
- else
- {
- Console.WriteLine("Ошибка!");
- }
- }
- private void ShowFishes()
- {
- Console.WriteLine("Количество рыб в аквариуме:" + _fishes.Count());
- foreach (var fish in _fishes)
- {
- Console.Write("Рыба возрастом " + fish.Age);
- if (fish.Age == 1)
- {
- Console.WriteLine(" год");
- }
- else if (fish.Age > 1 && fish.Age < 5)
- {
- Console.WriteLine(" года");
- }
- else if(fish.Age >= 5)
- {
- Console.WriteLine(" лет");
- }
- }
- }
- private void AddFish()
- {
- if(_fishes.Count() <= _maxSize)
- {
- Fish fish = new Fish();
- _fishes.Add(fish);
- }
- else
- {
- Console.WriteLine("Размер аквариума не позволяет добавить рыбу");
- }
- }
- private void DeleteFish()
- {
- if(_fishes.Count == 0)
- {
- Console.WriteLine("Аквариум пуст!");
- return;
- }
- if(_fishes.Count == 1)
- {
- _fishes.RemoveAt(0);
- return;
- }
- Console.Write("Какую рыбу вы хотите удалить?\nВвод: ");
- if(int.TryParse(Console.ReadLine(), out int number) && number <= _fishes.Count())
- {
- Console.WriteLine("Удаляем...");
- _fishes.RemoveAt(--number);
- }
- else
- {
- Console.WriteLine("Номер такой рыбы не существует!");
- }
- }
- private void IncreaseAgeFishes()
- {
- foreach (var fish in _fishes)
- {
- fish.IncreaseAge();
- }
- }
- }
- class Fish
- {
- public int Age { get; private set; }
- public Fish()
- {
- Age = 0;
- }
- public void IncreaseAge()
- {
- ++Age;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement