Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Bato
- {
- abstract class Product
- {
- public string Name { get; set; }
- public string Creator { get; set; }
- public double Price { get; set; }
- public int Discount { get; set; }
- public Product(string Name, string Creator, double Price, int Discount)
- {
- this.Name = Name;
- this.Creator = Creator;
- this.Price = Price;
- this.Discount = Discount;
- }
- public abstract double GetPrice();
- }
- class Food : Product
- {
- public int ExpirationTime { get; set; }
- public DateTime PackingDate { get; set; }
- public Food(string Name, string Creator, double Price, int Discount, int ExpirationTime, DateTime PackingDate) : base(Name, Creator, Price, Discount)
- {
- this.ExpirationTime = ExpirationTime;
- this.PackingDate = PackingDate;
- }
- public override double GetPrice()
- {
- if(Math.Abs(PackingDate.Day - DateTime.Today.Day) < 3)
- {
- return Price * (Discount / 100.0);
- }
- else
- {
- return Price;
- }
- }
- }
- class Chemical : Product
- {
- public string Type { get; set; }
- public Chemical(string Name, string Creator, double Price, int Discount, string Type) : base(Name, Creator, Price, Discount)
- {
- this.Type = Type;
- }
- public override double GetPrice()
- {
- if(DateTime.Today.Day % 2 == 0)
- {
- return Price * (Discount / 100.0);
- }
- else
- {
- return Price;
- }
- }
- }
- class Tools : Product
- {
- public double Weight { get; set; }
- public string UsableSeason { get; set; }
- public Tools(string Name, string Creator, double Price, int Discount, double Weight, string UsableSeason) : base(Name, Creator, Price, Discount)
- {
- this.Weight = Weight;
- this.UsableSeason = UsableSeason;
- }
- public override double GetPrice()
- {
- string thisSeason = "";
- int thisMonth = DateTime.Today.Month;
- if (thisMonth >= 3 && thisMonth <= 5)
- {
- thisSeason = "весна";
- }
- else if (thisMonth >= 6 && thisMonth <= 8)
- {
- thisSeason = "лето";
- }
- else if (thisMonth >= 9 && thisMonth <= 11)
- {
- thisSeason = "осень";
- }
- else
- {
- thisSeason = "зима";
- }
- if(thisSeason != UsableSeason)
- {
- return Price * (Discount / 100.0);
- }
- else
- {
- return Price;
- }
- }
- }
- // корзина
- class Bucket
- {
- private ArrayList list = new ArrayList();
- public void AddProduct(Product product)
- {
- list.Add(product);
- }
- public double GetSum()
- {
- double sum = 0;
- foreach(Product product in list)
- {
- sum += product.GetPrice();
- }
- if(sum > 2000)
- {
- return sum * 0.10;
- }
- else
- {
- return sum;
- }
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Food food1 = new Food("Хлебушек", "Бурятхлебпром", 25.5, 90, 3, new DateTime(2019, 4, 16));
- Food food2 = new Food("Пирожок сладкий", "Бурятхлебпром", 36.0, 80, 100, new DateTime(2019, 4, 16));
- Chemical chemical1 = new Chemical("Ушастый нянь", "Чистопром", 49.99, 75, "моющие средства");
- Chemical chemical2 = new Chemical("Абсолют Мыло", "Чистопром", 19.99, 85, "средства личной гигиены");
- Tools tools1 = new Tools("Молоток", "СБИК", 150.0, 90, 0.700, "лето");
- Tools tools2 = new Tools("Молоток", "УГИК", 150.0, 90, 0.700, "весна");
- Bucket bucket = new Bucket();
- bucket.AddProduct(food1);
- bucket.AddProduct(food2);
- bucket.AddProduct(chemical1);
- bucket.AddProduct(chemical2);
- bucket.AddProduct(tools1);
- bucket.AddProduct(tools2);
- Console.WriteLine("Сумма товаров в корзине = " + bucket.GetSum());
- Console.WriteLine(food1.Name + " " + food1.GetPrice());
- Console.WriteLine(food2.Name + " " + food2.GetPrice());
- Console.WriteLine(chemical1.Name + " " + chemical1.GetPrice());
- Console.WriteLine(chemical2.Name + " " + chemical2.GetPrice());
- Console.WriteLine(tools1.Name + " " + tools1.GetPrice());
- Console.WriteLine(tools2.Name + " " + tools2.GetPrice());
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment