SaNik74

Definition_of_delay

Oct 2nd, 2024
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.99 KB | None | 0 0
  1. using System.Data;
  2.  
  3. namespace Definition_of_delay
  4. {
  5.     internal class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Storehouse storehouse = new Storehouse();
  10.  
  11.             storehouse.ShowStews();
  12.  
  13.             storehouse.FindDelayStew();
  14.  
  15.             Console.WriteLine();
  16.  
  17.             storehouse.ShowStews();
  18.         }
  19.     }
  20.  
  21.     class Stew
  22.     {
  23.         public Stew(string name, DateTime dateProduction, int expiration)
  24.         {
  25.             Name = name;
  26.             DateProduction = dateProduction;
  27.             Expiration = expiration;
  28.         }
  29.  
  30.         public string Name { get; private set;}
  31.         public DateTime DateProduction { get; private set;}
  32.         public int Expiration { get; private set;}
  33.     }
  34.  
  35.     class Storehouse
  36.     {
  37.         private List<Stew> _stews = new List<Stew>();
  38.  
  39.         public Storehouse()
  40.         {
  41.             _stews.Add(new Stew("Мясокомбинат Курганский", new DateTime(2020, 2, 27), 5));
  42.             _stews.Add(new Stew("Главпродукт", new DateTime(2015, 8, 30), 3));
  43.             _stews.Add(new Stew("Скопинский мясоперерабатывающий комбинат", new DateTime(2024, 3, 14), 2));
  44.             _stews.Add(new Stew("Йошкар-Олинский мясокомбинат", new DateTime(2019, 4, 12), 1));
  45.             _stews.Add(new Stew("Любимый дом", new DateTime(2021, 12, 3), 3));
  46.         }
  47.  
  48.         public void ShowStews()
  49.         {
  50.             foreach (Stew stew in _stews)
  51.             {
  52.                 Console.WriteLine($"Название - \"{stew.Name}\", дата производства - {stew.DateProduction.ToShortDateString()}, срок годности {stew.Expiration}");
  53.             }
  54.         }
  55.  
  56.         public void FindDelayStew()
  57.         {
  58.             DateTime today = DateTime.Today;
  59.  
  60.             _stews = _stews.Where(stew => stew.DateProduction.AddYears(stew.Expiration) <= today).ToList();
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment