Advertisement
Rodunskiy

Untitled

Aug 18th, 2023
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.98 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class Program
  6. {
  7.     static void Main(string[] args)
  8.     {
  9.         Storage storage = new Storage();
  10.  
  11.         storage.Work();
  12.     }
  13. }
  14.  
  15. class Storage
  16. {
  17.     private List<CannedMeat> _cannedMeats;
  18.  
  19.     public Storage()
  20.     {
  21.         _cannedMeats = new List<CannedMeat>();
  22.  
  23.         AddCannedMeats();
  24.     }
  25.  
  26.     private void AddCannedMeats()
  27.     {
  28.         _cannedMeats.Add(new CannedMeat("Курица", 2020, 1));
  29.         _cannedMeats.Add(new CannedMeat("Говядина", 2020, 2));
  30.         _cannedMeats.Add(new CannedMeat("Свинина", 2020, 3));
  31.     }
  32.  
  33.     public void Work()
  34.     {
  35.         Console.WriteLine("Введите какой сегодня год?");
  36.         int year = Utils.ReadInt();
  37.  
  38.         var overdueСannedMeats = _cannedMeats.Where(cannedMeat => (cannedMeat.YearProduction + cannedMeat.ExpirationDate) < year).ToList();
  39.  
  40.         ShowInfo(overdueСannedMeats);
  41.     }
  42.  
  43.     public void ShowInfo(List<CannedMeat> cannedMeats)
  44.     {
  45.         foreach (var cannedMeat in cannedMeats)
  46.         {
  47.             Console.WriteLine($"Просрочено:{cannedMeat.Name}|Год производства{cannedMeat.YearProduction}|Срок годности {cannedMeat.ExpirationDate} год.");
  48.         }
  49.     }
  50. }
  51.  
  52. class CannedMeat
  53. {
  54.     public CannedMeat(string name, int yearProduction, int expirationDate)
  55.     {
  56.         Name = name;
  57.         YearProduction = yearProduction;
  58.         ExpirationDate = expirationDate;
  59.     }
  60.  
  61.     public string Name { get; private set; }
  62.     public int YearProduction { get; private set; }
  63.     public int ExpirationDate { get; private set; }
  64. }
  65.  
  66. class Utils
  67. {
  68.     public static int ReadInt()
  69.     {
  70.         int templateNumber;
  71.         string userInput = string.Empty;
  72.  
  73.         while (int.TryParse(userInput, out templateNumber) == false)
  74.         {
  75.             userInput = Console.ReadLine();
  76.         }
  77.  
  78.         return templateNumber;
  79.     }
  80. }
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement