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 Home_Work
- {
- class Program
- {
- static void Main()
- {
- Database database = new Database();
- database.Work();
- }
- }
- class Database
- {
- private List<Stew> _stews;
- private int _thisYear;
- public Database()
- {
- _stews = new List<Stew>();
- Fill();
- _thisYear = 2022;
- }
- public void Work()
- {
- bool isWorking = true;
- List<Stew> stews = _stews;
- int number;
- while(isWorking == true)
- {
- Console.WriteLine("Тушёнка: ");
- ShowSelection(stews);
- Console.WriteLine("\n1. Найти просроченные.\n2. Выход.");
- Console.Write("Введите команду: ");
- number = GetNumber();
- switch (number)
- {
- case 1:
- stews = FindExpiredStews();
- break;
- case 2:
- isWorking = false;
- break;
- default:
- Console.WriteLine("Неверная команда.");
- break;
- }
- Console.ReadKey();
- Console.Clear();
- }
- }
- private int GetNumber()
- {
- bool isConverted = false;
- int number = 0;
- string userInput;
- while (isConverted == false)
- {
- userInput = Console.ReadLine();
- isConverted = Int32.TryParse(userInput, out number);
- }
- return number;
- }
- private List<Stew> FindExpiredStews()
- {
- var sortedStews = _stews.Where(stew => stew.ProductionYear + stew.BestBeforeate < _thisYear).ToList();
- return sortedStews;
- }
- private void ShowSelection(List<Stew> stews)
- {
- foreach (Stew stew in stews)
- {
- stew.ShowInfo();
- }
- }
- private void Fill()
- {
- _stews.Add(new Stew());
- _stews.Add(new Stew());
- _stews.Add(new Stew());
- _stews.Add(new Stew());
- _stews.Add(new Stew());
- _stews.Add(new Stew());
- _stews.Add(new Stew());
- _stews.Add(new Stew());
- _stews.Add(new Stew());
- _stews.Add(new Stew());
- _stews.Add(new Stew());
- _stews.Add(new Stew());
- _stews.Add(new Stew());
- }
- }
- class Stew
- {
- private static Random _random;
- private NameStew _fullName;
- private int _productionYear;
- private int _bestBeforeate;
- static Stew()
- {
- _random = new Random();
- }
- public Stew()
- {
- int maxBestBeforeate = 10;
- int startYearProduced = 2010;
- int finishYearProduced = 2020;
- int countName = Enum.GetNames(typeof(NameStew)).Length;
- _fullName = (NameStew)_random.Next(countName);
- _bestBeforeate = _random.Next(maxBestBeforeate);
- _productionYear = _random.Next(startYearProduced, finishYearProduced);
- }
- public int ProductionYear => _productionYear;
- public int BestBeforeate => _bestBeforeate;
- public void ShowInfo()
- {
- Console.WriteLine($"{_fullName}. Дата игротовления: {_productionYear}. Срок годности: {_bestBeforeate}.");
- }
- }
- enum NameStew
- {
- OVA,
- MainProduct,
- Juicy,
- Finnika
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement