Advertisement
ostapdontstop

product

May 15th, 2019
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.98 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3.  
  4. namespace Tovar
  5. {
  6.     abstract class Tovar
  7.     {
  8.         public abstract void ShowInfo();
  9.  
  10.         public abstract bool IsOver(DateTime aDate);
  11.     }
  12.  
  13.     class Product : Tovar
  14.     {
  15.         string name;
  16.         double price;
  17.         DateTime dateFrom, dateOver;
  18.  
  19.         public Product(string aName, double aPrice, string strDateFrom, string strLifeDays)
  20.         {
  21.             this.name = aName;
  22.             this.price = aPrice;
  23.             this.dateFrom = Convert.ToDateTime(strDateFrom);
  24.             this.dateOver = Convert.ToDateTime(strLifeDays);
  25.         }
  26.  
  27.         public override void ShowInfo()
  28.         {
  29.             Console.WriteLine("Название: {0}\nЦена: {1}\nДата производства: {2}\nСрок годности: {3}", name, price, dateFrom.ToShortDateString(), dateOver.ToShortDateString());
  30.         }
  31.  
  32.         public override bool IsOver(DateTime aDate)
  33.         {
  34.             return DateTime.Compare(this.dateOver, aDate) < 0;
  35.         }
  36.     }
  37.  
  38.     class Partia : Tovar
  39.     {
  40.         string name;
  41.         double price;
  42.         int count;
  43.         DateTime dateFrom, dateOver;
  44.  
  45.         public Partia(string aName, double aPrice, int aCount, string strDateFrom, string strLifeDays)
  46.         {
  47.             this.name = aName;
  48.             this.price = aPrice;
  49.             this.count = aCount;
  50.             this.dateFrom = Convert.ToDateTime(strDateFrom);
  51.             this.dateOver = Convert.ToDateTime(strLifeDays);
  52.         }
  53.  
  54.         public override void ShowInfo()
  55.         {
  56.             Console.WriteLine("Название: {0}\nЦена: {1}\nКоличество: {2}\nДата производства: {3}\nСрок годности: {4}", name, price, count, dateFrom.ToShortDateString(), dateOver.ToShortDateString());
  57.         }
  58.  
  59.         public override bool IsOver(DateTime aDate)
  60.         {
  61.             return DateTime.Compare(this.dateOver, aDate) < 0;
  62.         }
  63.     }
  64.  
  65.  
  66.  
  67.     class Program
  68.     {
  69.         static void Main()
  70.         {
  71.  
  72.             Tovar[] arTovars = {
  73.                 new Product("макрона",  40,     "2019.02.18", "2019.06.18"),
  74.                 new Product("тушенка", 120,     "2019.01.18", "2019.08.18"),
  75.                 new Product("кабачьек", 160,    "2019.04.18", "2019.02.18"),
  76.                 new Partia("макроны", 3000, 50, "2019.05.10", "2019.06.10"),
  77.                 new Partia("огурцы", 2000, 100, "2019.04.18", "2019.05.17")
  78.             };
  79.  
  80.             DateTime localTime = DateTime.Now;
  81.             Console.WriteLine("Сегодняшняя дата: {0}\n------------", localTime.ToShortDateString());
  82.  
  83.             for (int i = 0; i < arTovars.Length; i++)
  84.             {
  85.                 arTovars[i].ShowInfo();
  86.                 if (arTovars[i].IsOver(localTime))
  87.                     Console.WriteLine("Товар просрочен!");
  88.  
  89.                 Console.WriteLine("------------");
  90.             }
  91.  
  92.         }
  93.  
  94.  
  95.     }
  96.  
  97.  
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement