Created
December 15, 2020 23:46
-
-
Save Hellhackee/8c2f4210c55a9f9a0acde1ee20e27b9d to your computer and use it in GitHub Desktop.
CS Light Lesson 43 (meat)
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
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
int currentYear = 2020; | |
Meat meat1 = new Meat("Микоян", 2008, 5); | |
Meat meat2 = new Meat("Мясофф", 2012, 10); | |
Meat meat3 = new Meat("Колбасы россии", 2016, 5); | |
Meat meat4 = new Meat("Мясной двор", 2003, 8); | |
Meat meat5 = new Meat("Дубки", 1998, 10); | |
Meat meat6 = new Meat("Консервный мир", 2020, 4); | |
List<Meat> meats = new List<Meat>() { meat1, meat2, meat3, meat4, meat5, meat6 }; | |
var notExpiredMeats = meats.Where(meat => meat.DateOfDelay() >= currentYear); | |
Console.WriteLine("Список всей тушенки: "); | |
foreach (var meat in meats) | |
{ | |
meat.ShowInfo(); | |
} | |
Console.WriteLine(); | |
Console.WriteLine("Список непросроченной тушенки: "); | |
foreach (var meat in notExpiredMeats) | |
{ | |
meat.ShowInfo(); | |
} | |
} | |
} | |
class Meat | |
{ | |
private string _name; | |
private int _productionDate; | |
private int _storageLife; | |
public Meat(string name, int productionDate, int storageLife) | |
{ | |
_name = name; | |
_productionDate = productionDate; | |
_storageLife = storageLife; | |
} | |
public int DateOfDelay() | |
{ | |
return _productionDate + _storageLife; | |
} | |
public void ShowInfo() | |
{ | |
Console.WriteLine($"Название: {_name}, дата производства {_productionDate}, срок годности {_storageLife} лет."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment