Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace LinqTrain
- {
- class Program
- {
- public static void Main()
- {
- int yearNow = 2000;
- List<Stew> stews = new List<Stew>();
- for (int i = 0; i < 60; i++)
- {
- stews.Add(new Stew());
- Console.WriteLine(stews[i].GetInfo(yearNow));
- }
- Console.ReadKey();
- Console.Clear();
- List<Stew> sortList = stews.Where(stew => stew.CheckFreshness(yearNow) == false).ToList<Stew>();
- Console.WriteLine($"Год сейчас - {yearNow} \nВывод просроченной тушенки");
- foreach (var stew in sortList)
- {
- Console.WriteLine(stew.GetInfo(yearNow));
- }
- Console.ReadKey();
- }
- }
- public static class RandomStatic
- {
- static private Random _rand = new Random();
- static public int GetNext(int min, int max)
- {
- return _rand.Next(min, max);
- }
- }
- public class Stew
- {
- public string Name { get; private set; }
- public int ProductionYear { get; private set; }
- public int ShelfLife { get; private set; }
- public Stew()
- {
- int index = RandomStatic.GetNext(0, 3);
- Name = new string[] { "Производитель 1", "Производитель 2", "Производитель 3" }[index];
- ProductionYear = new int[] { RandomStatic.GetNext(1970, 1975), RandomStatic.GetNext(1976, 1980), RandomStatic.GetNext(1980, 1985) }[index];
- ShelfLife = RandomStatic.GetNext(20, 35);
- }
- public bool CheckFreshness(int yearNow)
- {
- return ProductionYear + ShelfLife > yearNow;
- }
- public string GetInfo(int yearNow)
- {
- return $"{Name} - Произведена {ProductionYear} - срок годности {ShelfLife} - Истек {!CheckFreshness(yearNow)}";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement