Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Hoomework5
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<StewCan> stewCans = new List<StewCan> { };
- for (int i = 0; i < 10; i++)
- {
- stewCans.Add(new StewCan());
- }
- Console.WriteLine("--Все Банки--");
- foreach (var stewCan in stewCans)
- {
- stewCan.ShowInfo();
- stewCan.Expire();
- }
- var filteredStewCans = stewCans.Where(stewCan => stewCan.IsExpired == true);
- Console.WriteLine("--Просроченные Банки--");
- foreach (var stewCan in filteredStewCans)
- {
- stewCan.ShowInfo();
- }
- }
- }
- class StewCan
- {
- private string _name;
- private int _shelfLife;
- private int _ageOfManufacture;
- private readonly int _thisYear = 2021;
- private static Random _random = new Random();
- public bool IsExpired { get; private set; }
- public StewCan(string name = "simple stew can")
- {
- _name = name;
- _ageOfManufacture = _random.Next(1965, 2001);
- _shelfLife = _random.Next(21, 60);
- }
- public bool Expire()
- {
- IsExpired = _thisYear > (_ageOfManufacture + _shelfLife);
- return IsExpired;
- }
- public void ShowInfo()
- {
- Console.WriteLine($"Эта тушенка годится до {_ageOfManufacture + _shelfLife} года, а сейчас {_thisYear}.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment