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 HW_43_OOP_Aquarium
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- Aquarium aquarium = new Aquarium();
- while (true)
- {
- Console.WriteLine("Аквариум");
- Console.WriteLine($"Максимум рыбок - {aquarium.MaxFishCount} / {aquarium.CurrentFishCount}\n");
- ShowMenu();
- string userInput;
- userInput = Console.ReadLine();
- switch (userInput)
- {
- case "1":
- if (aquarium.CurrentFishCount < aquarium.MaxFishCount)
- {
- Console.Write("Введите название рыбки: ");
- string fishToAdd = Console.ReadLine();
- Console.Write("Введите возраст рыбки, если неизвестно, по умолчанию возраст с 0: ");
- int fishAge = Convert.ToInt32(Console.ReadLine());
- aquarium.AddFish(fishToAdd, fishAge);
- }
- else Console.WriteLine("В аквариуме уже нет места, уберите какую нибудь рыбку или оставьте так");
- break;
- case "2":
- Console.Write("Введите название рыбки ");
- string fishToRemove = Console.ReadLine();
- aquarium.RemoveFish(fishToRemove);
- break;
- case "3":
- aquarium.ShowFishInfo();
- break;
- default:
- break;
- }
- aquarium.MakeDayPass();
- aquarium.RemoveFish();
- Console.ReadKey();
- Console.Clear();
- }
- }
- public static void ShowMenu()
- {
- Console.WriteLine("1 - Добавить рыбку в аквариум\n2 - Достать рыбку из аквариума \n3 - Показать аквариум");
- }
- }
- class Aquarium
- {
- private List<Fish> _fishList = new List<Fish>();
- private int _maxFishCount = 3;
- private int _currentFishCount;
- public int MaxFishCount { get { return _maxFishCount; } }
- public int CurrentFishCount
- {
- get { return _currentFishCount; }
- set { _currentFishCount = value; }
- }
- public List<Fish> FishList
- {
- get { return _fishList; }
- set { _fishList = value; }
- }
- public void AddFish(string name, int age = 0)
- {
- _fishList.Add(new Fish(name, age));
- CurrentFishCount++;
- Console.WriteLine("Рыбка " + name + ". Добавлена");
- }
- public void RemoveFish(string name)
- {
- _fishList.RemoveAll(x => x.Specie == name);
- }
- public void RemoveFish()
- {
- _fishList.RemoveAll(x => x.Age > x.MaxAge);
- }
- public void ShowFishInfo()
- {
- foreach (var fish in _fishList)
- {
- Console.WriteLine($"Рыбка {fish.Specie}, возраст {fish.Age}");
- }
- }
- public void MakeDayPass()
- {
- foreach (var fish in _fishList)
- {
- fish.Age++;
- }
- }
- }
- class Fish
- {
- private string _specie;
- private int _age;
- private int _maxAge = 5;
- public Fish(string specie, int age)
- {
- _specie = specie;
- _age = age;
- }
- public string Specie
- {
- get { return _specie; }
- set { _specie = value; }
- }
- public int Age
- {
- get { return _age; }
- set { _age = value; }
- }
- public int MaxAge { get { return _maxAge; } }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement