Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class Program
- {
- static void Main(string[] args)
- {
- Storage storage = new Storage();
- storage.Work();
- }
- }
- class Storage
- {
- private List<CannedMeat> _cannedMeats;
- public Storage()
- {
- _cannedMeats = new List<CannedMeat>();
- AddCannedMeats();
- }
- private void AddCannedMeats()
- {
- _cannedMeats.Add(new CannedMeat("Курица", 2020, 1));
- _cannedMeats.Add(new CannedMeat("Говядина", 2020, 2));
- _cannedMeats.Add(new CannedMeat("Свинина", 2020, 3));
- }
- public void Work()
- {
- Console.WriteLine("Введите какой сегодня год?");
- int year = Utils.ReadInt();
- var overdueСannedMeats = _cannedMeats.Where(cannedMeat => (cannedMeat.YearProduction + cannedMeat.ExpirationDate) < year).ToList();
- ShowInfo(overdueСannedMeats);
- }
- public void ShowInfo(List<CannedMeat> cannedMeats)
- {
- foreach (var cannedMeat in cannedMeats)
- {
- Console.WriteLine($"Просрочено:{cannedMeat.Name}|Год производства{cannedMeat.YearProduction}|Срок годности {cannedMeat.ExpirationDate} год.");
- }
- }
- }
- class CannedMeat
- {
- public CannedMeat(string name, int yearProduction, int expirationDate)
- {
- Name = name;
- YearProduction = yearProduction;
- ExpirationDate = expirationDate;
- }
- public string Name { get; private set; }
- public int YearProduction { get; private set; }
- public int ExpirationDate { get; private set; }
- }
- class Utils
- {
- public static int ReadInt()
- {
- int templateNumber;
- string userInput = string.Empty;
- while (int.TryParse(userInput, out templateNumber) == false)
- {
- userInput = Console.ReadLine();
- }
- return templateNumber;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement