Anonim_999

Determination of delay

Nov 2nd, 2021 (edited)
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.71 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using System.Linq;
  5.  
  6. namespace ConsoleApp2
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             List<Stew> stews = new List<Stew>();
  13.             int yearToday = 2021;
  14.             Console.WriteLine($"Сейчас идет {yearToday} год");
  15.  
  16.             for (int i = 0; i < 10; i++)
  17.             {
  18.                 stews.Add(new Stew(yearToday));
  19.             }
  20.             Console.WriteLine("Вся тушенка: \n");
  21.  
  22.             foreach (var stew in stews)
  23.             {
  24.                 stew.ShowInfo();
  25.             }
  26.             Console.WriteLine("\nПросроченная тушенка:\n");
  27.             var expiredStew = stews.Where(stew => stew.ShelfLife < yearToday);
  28.  
  29.             foreach (var stew in expiredStew)
  30.             {
  31.                 stew.ShowInfo();
  32.             }
  33.         }
  34.     }
  35.  
  36.     class Stew
  37.     {
  38.         public int ShelfLife => _productionYear + _durationShelfLife;
  39.  
  40.         private string _name;
  41.         private int _productionYear;
  42.         private int _durationShelfLife = 5;
  43.  
  44.         public Stew(int yearToday)
  45.         {
  46.             Random random = new Random();
  47.             List<string> names = new List<string> { "Йошкар-Олинский", "Честный продукт", "БАРС", "ГРОДФУД" };
  48.             _name = names[random.Next(0, names.Count)];
  49.             _productionYear = random.Next(2010, yearToday);
  50.         }
  51.  
  52.         public void ShowInfo()
  53.         {
  54.             Console.WriteLine($"Название: {_name} || Год выпуска: {_productionYear} || Срок годности до: {ShelfLife}");
  55.         }
  56.     }
  57. }
Add Comment
Please, Sign In to add comment