Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Threading;
- using System.Linq;
- namespace ConsoleApp2
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<Stew> stews = new List<Stew>();
- int yearToday = 2021;
- Console.WriteLine($"Сейчас идет {yearToday} год");
- for (int i = 0; i < 10; i++)
- {
- stews.Add(new Stew(yearToday));
- }
- Console.WriteLine("Вся тушенка: \n");
- foreach (var stew in stews)
- {
- stew.ShowInfo();
- }
- Console.WriteLine("\nПросроченная тушенка:\n");
- var expiredStew = stews.Where(stew => stew.ShelfLife < yearToday);
- foreach (var stew in expiredStew)
- {
- stew.ShowInfo();
- }
- }
- }
- class Stew
- {
- public int ShelfLife => _productionYear + _durationShelfLife;
- private string _name;
- private int _productionYear;
- private int _durationShelfLife = 5;
- public Stew(int yearToday)
- {
- Random random = new Random();
- List<string> names = new List<string> { "Йошкар-Олинский", "Честный продукт", "БАРС", "ГРОДФУД" };
- _name = names[random.Next(0, names.Count)];
- _productionYear = random.Next(2010, yearToday);
- }
- public void ShowInfo()
- {
- Console.WriteLine($"Название: {_name} || Год выпуска: {_productionYear} || Срок годности до: {ShelfLife}");
- }
- }
- }
Add Comment
Please, Sign In to add comment