Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Task55
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- Storage storage = new Storage();
- storage.Work();
- }
- }
- class Storage
- {
- private List<Product> _products;
- private int _currentYear;
- public Storage()
- {
- _currentYear = 2022;
- _products = new List<Product>();
- _products.Add(new Product("Говяжья Тушёнка", 2019, 8));
- _products.Add(new Product("Свиная Тушёнка", 2020, 7));
- _products.Add(new Product("Куриная Тушёнка", 2015, 5));
- _products.Add(new Product("Утиная Тушёнка", 2010, 9));
- _products.Add(new Product("Гусиная Тушёнка", 2017, 1));
- _products.Add(new Product("Индюшиная Тушёнка", 2018, 5));
- }
- public void Work()
- {
- string wholeStock =
- "Доступный запас на складе.";
- string expiredProducts =
- "Просроченные: ";
- Console.WriteLine(wholeStock);
- Show(_products);
- Console.WriteLine();
- Console.WriteLine(expiredProducts);
- ShowExpiredProducts();
- }
- private void ShowExpiredProducts()
- {
- List<Product> expiredProducts = new List<Product>();
- expiredProducts = _products.Where(product => product.YearProduction + product.BestBeforeDate <= _currentYear).ToList();
- Show(expiredProducts);
- }
- private void Show(List<Product> products)
- {
- foreach (var product in products)
- {
- product.Show();
- }
- }
- }
- class Product
- {
- public string Name { get; private set; }
- public int YearProduction { get; private set; }
- public int BestBeforeDate { get; private set; }
- public Product(string name, int yearProduction, int bestBeforeDate)
- {
- Name = name;
- YearProduction = yearProduction;
- BestBeforeDate = bestBeforeDate;
- }
- public void Show()
- {
- Console.WriteLine(
- $"Кароточка продукта :\n" +
- $"Наименование : {Name}\n" +
- $"Год производства : {YearProduction}\n" +
- $"Срок годности : {BestBeforeDate}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement