Skip to content

Instantly share code, notes, and snippets.

@tsk-arh
Last active February 2, 2024 16:02
Show Gist options
  • Save tsk-arh/20e51cff2b75fbb383eb32abaa0a3598 to your computer and use it in GitHub Desktop.
Save tsk-arh/20e51cff2b75fbb383eb32abaa0a3598 to your computer and use it in GitHub Desktop.
ЗАДАНИЕ Определение просрочки
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp4
{
internal class Program
{
static void Main(string[] args)
{
List<Stew> stewCollection = new List<Stew> {
new Stew ("Петров Петр Петрович", 1968, 5),
new Stew ("Сидоров Сидор Сидорыч", 2021, 4),
new Stew ("Байден Байден Байденович", 1938, 5),
new Stew ("Лямкин Дрист Корнетыч", 1984, 10),
new Stew ("Кабздец Христофор Василич", 2020, 5),
new Stew ("Гусь Чур Федотыч", 2009, 20),
new Stew ("Тяпкин Лопат Копайтич", 1992, 40),
new Stew ("Рябинин Ранетка Василич", 2018, 6),
new Stew ("Жмотин Жил Зажильевич", 2007, 20),
new Stew ("Корявкин Писака Картофелич", 2018, 5),
};
int thisYear = 2024;
var expiredProducts = stewCollection.Where(stew => stew.ProductionYear + stew.Expiration < thisYear).ToList();
WriteExpiredProducts(expiredProducts);
Console.ReadLine();
}
private static void WriteExpiredProducts(List<Stew> stewCollection)
{
Console.WriteLine("Просроченные продукты: \n");
for (int i = 0; i < stewCollection.Count; i++)
{
int serialNumber = i + 1;
Console.WriteLine($"{serialNumber}. Название продукта: {stewCollection[i].Name} \nГод выпуска: {stewCollection[i].ProductionYear} \nСрок годности {stewCollection[i].Expiration}");
}
}
}
class Stew
{
public Stew(string name, int productionYear, int expiration)
{
Name = name;
ProductionYear = productionYear;
Expiration = expiration;
}
public string Name { get; private set; }
public int ProductionYear { get; private set; }
public int Expiration { get; private set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment