Laitofai

Батоха тащи

May 16th, 2019
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.37 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Bato
  9. {
  10.     abstract class Product
  11.     {
  12.         public string Name { get; set; }
  13.         public string Creator { get; set; }
  14.         public double Price { get; set; }
  15.         public int Discount { get; set; }
  16.  
  17.         public Product(string Name, string Creator, double Price, int Discount)
  18.         {
  19.             this.Name = Name;
  20.             this.Creator = Creator;
  21.             this.Price = Price;
  22.             this.Discount = Discount;
  23.         }
  24.  
  25.         public abstract double GetPrice();
  26.     }
  27.  
  28.     class Food : Product
  29.     {
  30.         public int ExpirationTime { get; set; }
  31.         public DateTime PackingDate { get; set; }
  32.        
  33.         public Food(string Name, string Creator, double Price, int Discount, int ExpirationTime, DateTime PackingDate) : base(Name, Creator, Price, Discount)
  34.         {
  35.             this.ExpirationTime = ExpirationTime;
  36.             this.PackingDate = PackingDate;
  37.         }
  38.  
  39.         public override double GetPrice()
  40.         {
  41.             if(Math.Abs(PackingDate.Day - DateTime.Today.Day) < 3)
  42.             {
  43.                 return Price * (Discount / 100.0);
  44.             }
  45.             else
  46.             {
  47.                 return Price;
  48.             }
  49.         }
  50.     }
  51.  
  52.     class Chemical : Product
  53.     {
  54.         public string Type { get; set; }
  55.  
  56.         public Chemical(string Name, string Creator, double Price, int Discount, string Type) : base(Name, Creator, Price, Discount)
  57.         {
  58.             this.Type = Type;
  59.         }
  60.  
  61.         public override double GetPrice()
  62.         {
  63.             if(DateTime.Today.Day % 2 == 0)
  64.             {
  65.                 return Price * (Discount / 100.0);
  66.             }
  67.             else
  68.             {
  69.                 return Price;
  70.             }
  71.         }
  72.     }
  73.  
  74.     class Tools : Product
  75.     {
  76.         public double Weight { get; set; }
  77.         public string UsableSeason { get; set; }
  78.  
  79.         public Tools(string Name, string Creator, double Price, int Discount, double Weight, string UsableSeason) : base(Name, Creator, Price, Discount)
  80.         {
  81.             this.Weight = Weight;
  82.             this.UsableSeason = UsableSeason;
  83.         }
  84.  
  85.         public override double GetPrice()
  86.         {
  87.             string thisSeason = "";
  88.             int thisMonth = DateTime.Today.Month;
  89.             if (thisMonth >= 3 && thisMonth <= 5)
  90.             {
  91.                 thisSeason = "весна";
  92.             }
  93.             else if (thisMonth >= 6 && thisMonth <= 8)
  94.             {
  95.                 thisSeason = "лето";
  96.             }
  97.             else if (thisMonth >= 9 && thisMonth <= 11)
  98.             {
  99.                 thisSeason = "осень";
  100.             }
  101.             else
  102.             {
  103.                 thisSeason = "зима";
  104.             }
  105.  
  106.             if(thisSeason != UsableSeason)
  107.             {
  108.                 return Price * (Discount / 100.0);
  109.             }
  110.             else
  111.             {
  112.                 return Price;
  113.             }
  114.         }
  115.     }
  116.  
  117.     // корзина
  118.     class Bucket
  119.     {
  120.         private ArrayList list = new ArrayList();
  121.  
  122.         public void AddProduct(Product product)
  123.         {
  124.             list.Add(product);
  125.         }
  126.  
  127.         public double GetSum()
  128.         {
  129.             double sum = 0;
  130.             foreach(Product product in list)
  131.             {
  132.                 sum += product.GetPrice();
  133.             }
  134.             if(sum > 2000)
  135.             {
  136.                 return sum * 0.10;
  137.             }
  138.             else
  139.             {
  140.                 return sum;
  141.             }
  142.         }
  143.     }
  144.  
  145.     class Program
  146.     {
  147.         static void Main(string[] args)
  148.         {
  149.             Food food1 = new Food("Хлебушек", "Бурятхлебпром", 25.5, 90, 3, new DateTime(2019, 4, 16));
  150.             Food food2 = new Food("Пирожок сладкий", "Бурятхлебпром", 36.0, 80, 100, new DateTime(2019, 4, 16));
  151.             Chemical chemical1 = new Chemical("Ушастый нянь", "Чистопром", 49.99, 75, "моющие средства");
  152.             Chemical chemical2 = new Chemical("Абсолют Мыло", "Чистопром", 19.99, 85, "средства личной гигиены");
  153.             Tools tools1 = new Tools("Молоток", "СБИК", 150.0, 90, 0.700, "лето");
  154.             Tools tools2 = new Tools("Молоток", "УГИК", 150.0, 90, 0.700, "весна");
  155.  
  156.             Bucket bucket = new Bucket();
  157.  
  158.             bucket.AddProduct(food1);
  159.             bucket.AddProduct(food2);
  160.             bucket.AddProduct(chemical1);
  161.             bucket.AddProduct(chemical2);
  162.             bucket.AddProduct(tools1);
  163.             bucket.AddProduct(tools2);
  164.             Console.WriteLine("Сумма товаров в корзине = " + bucket.GetSum());
  165.  
  166.             Console.WriteLine(food1.Name + " " + food1.GetPrice());
  167.             Console.WriteLine(food2.Name + " " + food2.GetPrice());
  168.             Console.WriteLine(chemical1.Name + " " + chemical1.GetPrice());
  169.             Console.WriteLine(chemical2.Name + " " + chemical2.GetPrice());
  170.             Console.WriteLine(tools1.Name + " " + tools1.GetPrice());
  171.             Console.WriteLine(tools2.Name + " " + tools2.GetPrice());
  172.             Console.ReadKey();
  173.         }
  174.     }
  175. }
Advertisement
Add Comment
Please, Sign In to add comment