Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Определение_просрочки
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- Storage storage = new Storage();
- storage.Work();
- }
- }
- class Storage
- {
- private List<Stew> _stewBox = new List<Stew>();
- public Storage()
- {
- _stewBox.Add(new Stew("Микоян", 1986, 20));
- _stewBox.Add(new Stew("Вкусвилл", 2020, 5));
- _stewBox.Add(new Stew("Главпродукт", 2011, 10));
- _stewBox.Add(new Stew("Слонимский мясокомбинат", 2023, 6));
- _stewBox.Add(new Stew("Кронидов", 2005, 15));
- _stewBox.Add(new Stew("Гродфуд", 2010, 17));
- _stewBox.Add(new Stew("Барс", 2017, 4));
- _stewBox.Add(new Stew("Совок", 2016, 5));
- }
- public void Work()
- {
- Console.WriteLine("Продукция на складе: ");
- ShowAllProducts();
- Console.WriteLine("\nПросрочка: ");
- SearchExpiredProducts();
- }
- private void SearchExpiredProducts()
- {
- int currentYear = 2024;
- var expiredProducts = _stewBox.Where(stew => (stew.ProductionYear + stew.ShelfLife) < currentYear);
- foreach (var expired in expiredProducts)
- {
- expired.ShowDescription();
- }
- }
- private void ShowAllProducts()
- {
- foreach (var stew in _stewBox)
- {
- stew.ShowDescription();
- }
- }
- }
- class Stew
- {
- public Stew(string title, int productionYear, int shelfLife)
- {
- Title = title;
- ProductionYear = productionYear;
- ShelfLife = shelfLife;
- }
- public string Title { get; private set; }
- public int ProductionYear { get; private set; }
- public int ShelfLife { get; private set; }
- public void ShowDescription()
- {
- Console.WriteLine($"Название: {Title} Год выпуска: {ProductionYear} Срок годности: {ShelfLife}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement