Skip to content

Instantly share code, notes, and snippets.

@talatari
Last active November 14, 2023 07:46
Show Gist options
  • Save talatari/45e1458ed791a951b4de7a784b9b97bc to your computer and use it in GitHub Desktop.
Save talatari/45e1458ed791a951b4de7a784b9b97bc to your computer and use it in GitHub Desktop.
Task 55: Determination Of Expired
namespace DeterminationOfExpired
{
public static class Program
{
public static void Main()
{
SuperMarket superMarket = new SuperMarket();
Database database = new Database();
superMarket.Work(database);
}
}
public class Database
{
private readonly List<Stew> _stews = new();
public Database()
{
Initialization();
}
public List<Stew> GetStews() => new(_stews);
private void Initialization()
{
_stews.Add(new Stew("Horns and Hooves", 2019, 5));
_stews.Add(new Stew("Mikoyan", 2021, 3));
_stews.Add(new Stew("OVA", 2018, 4));
_stews.Add(new Stew("OVA", 2023, 4));
_stews.Add(new Stew("Horns and Hooves", 2019, 5));
_stews.Add(new Stew("Mikoyan", 2000, 3));
_stews.Add(new Stew("Mikoyan", 2017, 3));
_stews.Add(new Stew("Horns and Hooves", 2001, 5));
_stews.Add(new Stew("OVA", 2018, 4));
_stews.Add(new Stew("Horns and Hooves", 2023, 5));
_stews.Add(new Stew("Mikoyan", 2022, 3));
}
}
public class Stew
{
public Stew(string name, int releaseYear, int expiration)
{
Name = name;
ReleaseYear = releaseYear;
Expiration = expiration;
}
public string Name { get; }
public int ReleaseYear { get; }
public int Expiration { get; }
}
public class SuperMarket
{
private bool _isWork = true;
private Database _database;
public void Work(Database database)
{
_database = database;
IEnumerable<Stew> expiredProductions;
while (_isWork)
{
Console.Clear();
expiredProductions = FindExpiredProductions(_database.GetStews());
Show(expiredProductions);
Console.ReadKey();
}
}
private IEnumerable<Stew> FindExpiredProductions(List<Stew> stews) =>
stews.Where(stew => DateTime.Now.Year - stew.ReleaseYear > stew.Expiration);
private void Show(IEnumerable<Stew> stews)
{
Console.WriteLine();
foreach (Stew stew in stews)
{
Console.WriteLine($"Name: {stew.Name}, " +
$"ReleaseYear: {stew.ReleaseYear}, " +
$"ExpirationDate: {stew.Expiration}");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment