Created
May 29, 2024 20:24
-
-
Save EreminAndrei/5509555dba21af64dcdcfed5cec5e075 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 Project3 | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
FoodDatabase foodDatabase = new FoodDatabase(); | |
foodDatabase.Work(); | |
} | |
} | |
class UserUtils | |
{ | |
private static Random s_random = new Random(); | |
public static int GenerateRandomNumber(int min, int max) | |
{ | |
return s_random.Next(min, max); | |
} | |
} | |
class FoodDatabase | |
{ | |
private List<Food> _foods; | |
public FoodDatabase() | |
{ | |
int maxNumberOfFood = 25; | |
int minYaerOfProduction = 2000; | |
int maxYearOfProduction = 2024; | |
int minShelfLifePeriod = 5; | |
int maxShelfLifePeriod = 15; | |
List<Food> foods = new List<Food>(); | |
string[] names = new string[] {"Из свинины", "Из говядины", "Из баранины", "Из мяса птицы"}; | |
for (int i = 0; i < maxNumberOfFood; i++) | |
{ | |
foods.Add(new Food(names[UserUtils.GenerateRandomNumber(0, names.Length)], UserUtils.GenerateRandomNumber(minYaerOfProduction, maxYearOfProduction), | |
UserUtils.GenerateRandomNumber(minShelfLifePeriod, maxShelfLifePeriod))); | |
} | |
_foods = foods; | |
} | |
public void Work() | |
{ | |
Console.WriteLine("Добро пожаловать на склад тушенки."); | |
ShowAllInfo(_foods); | |
Console.WriteLine(); | |
ShowNotEdibleFood(); | |
} | |
private void ShowAllInfo(List<Food> foods) | |
{ | |
foreach (var food in foods) | |
{ | |
food.ShowInfo(); | |
} | |
Console.WriteLine(); | |
} | |
private void ShowNotEdibleFood() | |
{ | |
Console.WriteLine("Эту тушенку лучше не брать она просрочена!"); | |
int YearNow = 2024; | |
var notEdibleFoods = _foods.Where(food => food.YearOfProduction + food.ShelfLifePeriod <= YearNow).ToList(); | |
ShowAllInfo(notEdibleFoods); | |
} | |
} | |
class Food | |
{ | |
public Food(string name, int yearOfProduction, int shelfLifePeriod) | |
{ | |
Name = name; | |
YearOfProduction = yearOfProduction; | |
ShelfLifePeriod = shelfLifePeriod; | |
} | |
public string Name { get; private set; } | |
public int YearOfProduction { get; private set; } | |
public int ShelfLifePeriod { get; private set; } | |
public void ShowInfo() | |
{ | |
Console.WriteLine($"Тип тушенки: {Name}, Год производства: {YearOfProduction}, Срок Хранения: {ShelfLifePeriod} лет"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment