Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- namespace Tovar
- {
- abstract class Tovar
- {
- public abstract void ShowInfo();
- public abstract bool IsOver(DateTime aDate);
- }
- class Product : Tovar
- {
- string name;
- double price;
- DateTime dateFrom, dateOver;
- public Product(string aName, double aPrice, string strDateFrom, string strLifeDays)
- {
- this.name = aName;
- this.price = aPrice;
- this.dateFrom = Convert.ToDateTime(strDateFrom);
- this.dateOver = Convert.ToDateTime(strLifeDays);
- }
- public override void ShowInfo()
- {
- Console.WriteLine("Название: {0}\nЦена: {1}\nДата производства: {2}\nСрок годности: {3}", name, price, dateFrom.ToShortDateString(), dateOver.ToShortDateString());
- }
- public override bool IsOver(DateTime aDate)
- {
- return DateTime.Compare(this.dateOver, aDate) < 0;
- }
- }
- class Partia : Tovar
- {
- string name;
- double price;
- int count;
- DateTime dateFrom, dateOver;
- public Partia(string aName, double aPrice, int aCount, string strDateFrom, string strLifeDays)
- {
- this.name = aName;
- this.price = aPrice;
- this.count = aCount;
- this.dateFrom = Convert.ToDateTime(strDateFrom);
- this.dateOver = Convert.ToDateTime(strLifeDays);
- }
- public override void ShowInfo()
- {
- Console.WriteLine("Название: {0}\nЦена: {1}\nКоличество: {2}\nДата производства: {3}\nСрок годности: {4}", name, price, count, dateFrom.ToShortDateString(), dateOver.ToShortDateString());
- }
- public override bool IsOver(DateTime aDate)
- {
- return DateTime.Compare(this.dateOver, aDate) < 0;
- }
- }
- class Program
- {
- static void Main()
- {
- Tovar[] arTovars = {
- new Product("макрона", 40, "2019.02.18", "2019.06.18"),
- new Product("тушенка", 120, "2019.01.18", "2019.08.18"),
- new Product("кабачьек", 160, "2019.04.18", "2019.02.18"),
- new Partia("макроны", 3000, 50, "2019.05.10", "2019.06.10"),
- new Partia("огурцы", 2000, 100, "2019.04.18", "2019.05.17")
- };
- DateTime localTime = DateTime.Now;
- Console.WriteLine("Сегодняшняя дата: {0}\n------------", localTime.ToShortDateString());
- for (int i = 0; i < arTovars.Length; i++)
- {
- arTovars[i].ShowInfo();
- if (arTovars[i].IsOver(localTime))
- Console.WriteLine("Товар просрочен!");
- Console.WriteLine("------------");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement