Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace CSLightFirst
- {
- class Program
- {
- private static void Main()
- {
- List<Stew> stewSet = GenerateStewSet();
- while (true)
- {
- Console.WriteLine("Выберите, что Вам нужно сделать:\n" +
- " 1 - Показать просроченную тушенку\n" +
- " 2 - Показать весь набор тушенки\n");
- Console.Write("Ваш ответ: ");
- switch (Console.ReadLine())
- {
- case "1":
- MakeShelfLifeSelection(stewSet);
- break;
- case "2":
- ShowSelection(stewSet, "Набор тушенки состоит из:\n");
- break;
- default:
- Console.WriteLine("Некорректное введенное значение, попробуйте ещё раз...");
- break;
- }
- }
- }
- private static void MakeShelfLifeSelection(IEnumerable<Stew> stewSet)
- {
- int currentYear = 2020;
- ShowSelection(stewSet.Where(stew => stew.ProductionYear + stew.ShelfLife < currentYear),
- "Просроченная тушенка:\n");
- }
- private static void ShowSelection(IEnumerable<Stew> selection, string text = "")
- {
- Console.Clear();
- Console.WriteLine(text);
- foreach (Stew stew in selection)
- stew.ShowInfo();
- }
- private static List<Stew> GenerateStewSet()
- {
- Random rand = new Random();
- string[] names = { "Честный продукт", "БАРС", "Главпродукт", "ГРОДФУД", "Ремит" };
- List<Stew> stewSet = new List<Stew>(rand.Next(5, 10));
- for (int i = 0; i < stewSet.Capacity; i++)
- stewSet.Add(new Stew(
- names[rand.Next(0, names.Length)],
- rand.Next(2016, 2019),
- rand.Next(1, 6)));
- return stewSet;
- }
- }
- class Stew
- {
- public string Name { get; }
- public int ProductionYear { get; }
- public int ShelfLife { get; }
- public Stew(string name, int productionYear, int shelfLife)
- {
- Name = name;
- ProductionYear = productionYear;
- ShelfLife = shelfLife;
- }
- public void ShowInfo()
- {
- Console.WriteLine($" Тушенка: {Name}\n" +
- $" Год производства: {ProductionYear}\n" +
- $" Срок годности: {ShelfLife}\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement