Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Скидки
- {
- class Program
- {
- static void Main(string[] args)
- {
- /* На кассу приходит покупатель, кассир создаёт новый чек.
- * В чеке есть возможность:
- * 1. Добавить продукт*, если этот продукт уже есть в чеке, то у него просто увеличится количество.
- * 2. Добавить новую персональную скидку (с учётом того, что если до этого какая-либо скидка данного типа
- * применялась, то берётся большая)
- * 3. Установить дневную скидку с нижним пределом общей стоимости чека.
- * 4. Распечатать чек с учётом пунктов 2 и 3.
- * *под продуктом подразумевается его полная информация: название, стоимость, скидка единицу товара*
- */
- }
- }
- #region Система классов
- #region Interfaces
- interface ICalculateDiscount
- {
- void CalculateDiscount();
- }
- interface IProductManager
- {
- void AddProductThisType();
- }
- #endregion
- #region Class Product
- public class Product: ICalculateDiscount, IProductManager
- {
- public string _productName;
- public double _price;
- public int _discount;
- public int _count;
- public double _totalPrice;
- public Product(string name, double price, int discount, int count)
- {
- _productName = name;
- _price = price;
- _discount = discount;
- _count = count;
- _totalPrice = price * count;
- }
- public void AddProductThisType()
- {
- _count++;
- _totalPrice += _price;
- }
- public void CalculateDiscount() //считает цену на товар в рублях с учетом скидки на данный товар
- {
- this._totalPrice -= _totalPrice * (_discount/100);
- }
- }
- #endregion
- public struct DayDiscount
- {
- public int _discount;
- public double _infTotalSum;
- public DayDiscount(int discount, double infTotalSum)
- {
- _discount = discount;
- _infTotalSum = infTotalSum;
- }
- }
- public class Check : ICalculateDiscount
- {
- public List<Product> _products;
- int _discountPersonal;
- double _totalSumCheck;
- DayDiscount dayDiscount;
- public Check()
- {
- _products = new List<Product>();
- _totalSumCheck = 0;
- dayDiscount = new DayDiscount(0, int.MaxValue);
- }
- public void AddElementToCheck(Product newProduct)
- {
- bool FindElement = false;
- foreach(var product in _products)
- {
- if(newProduct._productName == product._productName)
- {
- product.AddProductThisType();
- FindElement = true;
- break;
- }
- }
- if(!FindElement)
- {
- _products.Add(newProduct);
- }
- _products.Add(newProduct);
- }
- public void SetDayDiscount(DayDiscount dayDiscountInThisDay)
- {
- dayDiscount = dayDiscountInThisDay;
- }
- public void PrintCheck()
- {
- CalculateDiscount();
- Console.WriteLine("*Пииип-пииип* Идет печать чека...");
- Console.WriteLine($"С Вас {_totalSumCheck}, пожалуйста!");
- }
- public void CalculateDiscount()
- {
- _totalSumCheck -= _totalSumCheck * (_discountPersonal/100);
- if (dayDiscount._infTotalSum < _totalSumCheck)
- {
- _totalSumCheck -= _totalSumCheck * (dayDiscount._discount / 100);
- }
- }
- public void AddNewTypeDiscount(int newDiscount)
- {
- if(newDiscount>_discountPersonal)
- {
- _discountPersonal = newDiscount;
- }
- }
- }
- #endregion
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement