Skip to content

Instantly share code, notes, and snippets.

@ShamilAitov
Last active August 9, 2023 22:49
Show Gist options
  • Save ShamilAitov/39af02478749276387ee7179261571b7 to your computer and use it in GitHub Desktop.
Save ShamilAitov/39af02478749276387ee7179261571b7 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
namespace LINQ6Задание
{
internal class Program
{
static void Main(string[] args)
{
Administration administration = new Administration();
administration.Play();
}
}
class Administration
{
private List<Stew> _stews = new List<Stew>();
private int _currentYear = 2023;
public Administration()
{
FillStews();
}
public void Play()
{
Console.WriteLine("Все тушенки в наличии: ");
ShowStews(_stews);
Console.WriteLine("Все просроченные тушенки: ");
var expiredStews = _stews.Where(Stew => Stew.ExpirationYear < _currentYear).ToList();
ShowStews(expiredStews);
}
private void FillStews()
{
_stews.Add(new Stew("Говядина", 2000, 2019));
_stews.Add(new Stew("Конина ", 2001, 2020));
_stews.Add(new Stew("Баранина", 2017, 2026));
_stews.Add(new Stew("Индилайт", 2016, 2027));
_stews.Add(new Stew("Тушинка", 2006, 2020));
_stews.Add(new Stew("Грудинка", 2007, 2022));
_stews.Add(new Stew("Буженинка", 2009, 2023));
_stews.Add(new Stew("Курятинка", 2019, 2024));
_stews.Add(new Stew("Долговечная", 2018, 2021));
_stews.Add(new Stew("Сел и съел", 2019, 2022));
}
private void ShowStews(List<Stew> stews)
{
if (stews.Any())
{
foreach (var stew in stews)
{
stew.ShowInfo();
}
Console.WriteLine();
}
else
{
Console.WriteLine("Список пуст!");
}
}
}
class Stew
{
public Stew(string name, int yearManufacture, int expirationYear)
{
Name = name;
YearManufacture = yearManufacture;
ExpirationYear = expirationYear;
}
public string Name { get; private set; }
public int YearManufacture { get; private set; }
public int ExpirationYear { get; private set; }
public void ShowInfo()
{
Console.WriteLine($"{Name}: Год изготовления ({YearManufacture} г.) - Срок годности ({ExpirationYear} г.)");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment