-
-
Save Dnk095/218c656c53c85a7f2c661dc9e99e6112 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace _7_5 | |
{ | |
internal class Program | |
{ | |
static void Main() | |
{ | |
ConsoleMenu menu = new ConsoleMenu(); | |
menu.SordExpiration(); | |
} | |
} | |
class Product | |
{ | |
public Product(string name, int dateOfProduction, int exporationDate) | |
{ | |
Name = name; | |
DateOfProduction = dateOfProduction; | |
ExpirationDate = exporationDate; | |
} | |
public string Name { get; } | |
public int DateOfProduction { get; } | |
public int ExpirationDate { get; } | |
} | |
class BoxProduct | |
{ | |
private List<Product> _products; | |
public BoxProduct() | |
{ | |
_products = new List<Product>(); | |
Fill(); | |
} | |
public List<Product> GetList() | |
{ | |
return new List<Product>(_products); | |
} | |
private void Fill() | |
{ | |
_products.Add(new Product("Тушенка", 2021, 2)); | |
_products.Add(new Product("Тушенка", 2019, 1)); | |
_products.Add(new Product("Тушенка", 2024, 2)); | |
_products.Add(new Product("Тушенка", 2017, 3)); | |
_products.Add(new Product("Тушенка", 2014, 2)); | |
_products.Add(new Product("Тушенка", 2010, 2)); | |
_products.Add(new Product("Тушенка", 2015, 1)); | |
_products.Add(new Product("Тушенка", 2018, 4)); | |
_products.Add(new Product("Тушенка", 2022, 2)); | |
_products.Add(new Product("Тушенка", 2020, 1)); | |
_products.Add(new Product("Тушенка", 2019, 2)); | |
_products.Add(new Product("Тушенка", 2015, 2)); | |
_products.Add(new Product("Тушенка", 2013, 1)); | |
_products.Add(new Product("Тушенка", 2014, 2)); | |
_products.Add(new Product("Тушенка", 2018, 1)); | |
_products.Add(new Product("Тушенка", 2007, 1)); | |
} | |
} | |
class ConsoleMenu | |
{ | |
private BoxProduct _product; | |
public ConsoleMenu() | |
{ | |
_product = new BoxProduct(); | |
} | |
public void SordExpiration() | |
{ | |
List<Product> products = _product.GetList(); | |
int date = DateTime.Now.Year; | |
Console.WriteLine("Список продуктов"); | |
ShowAllProducts(products); | |
List<Product> expirationProduct = products.Where | |
(product => product.DateOfProduction + product.ExpirationDate < date). | |
OrderBy(product => product.DateOfProduction).ToList(); | |
Console.WriteLine("\nСписок просрочки"); | |
ShowAllProducts(expirationProduct); | |
} | |
private void ShowAllProducts(List<Product> products) | |
{ | |
for (int i = 0; i < products.Count; i++) | |
Console.WriteLine($"{i + 1} {products[i].Name}, год изготовления - - " + | |
$"{products[i].DateOfProduction}, срок годности - {products[i].ExpirationDate} год"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment