Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Runtime.CompilerServices;
- using System.Security.Cryptography;
- using System.Security.Policy;
- class Program
- {
- static void Main(string[] args)
- {
- Supermarket supermarket = new Supermarket();
- supermarket.SellingProducts();
- }
- }
- class Supermarket
- {
- Random random = new Random();
- private int _supermarketMoney = 0;
- Basket basket = new Basket();
- private Queue<Buyer> _buyers = new Queue<Buyer>();
- private List<Product> _products = new List<Product>();
- public Supermarket()
- {
- _products.Add(new Product("Банан", 10));
- _products.Add(new Product("Яблоко", 5));
- _products.Add(new Product("Груша", 15));
- _products.Add(new Product("Апельсин", 20));
- _products.Add(new Product("Арбуз", 30));
- CreateNewBuyer(5);
- }
- public void CreateNewBuyer(int count)
- {
- int minMoney = 30;
- int maxMoney = 51;
- for (int i = 0; i < count; i++)
- {
- _buyers.Enqueue(new Buyer(random.Next(minMoney,maxMoney)));
- }
- }
- public void GiveProducts()
- {
- Product product = null;
- int _maxbuyCount = 6;
- int _minbuyCount = 2;
- int productCount = random.Next(_minbuyCount,_maxbuyCount);
- for (int i = 0; i < productCount; i++)
- {
- int randomIndex = random.Next(_products.Count);
- product = _products[randomIndex];
- basket.TakeProducts(product);
- }
- }
- public void SellingProducts()
- {
- bool isBuy = true;
- int productsAllPrice;
- Console.WriteLine($"Сегодня супермаркет заработал {_supermarketMoney} монет.");
- Buyer buyer = _buyers.Dequeue();
- GiveProducts();
- productsAllPrice = basket.AllPrice();
- Console.WriteLine($"К кассе подошёл покупатель. У него {buyer.Money} монет. \nОн хочет купить продукты на сумму {productsAllPrice} монет.");
- while (isBuy)
- {
- if (buyer.Money < productsAllPrice)
- {
- Console.WriteLine("У покупателя недостаточно монет! Нужно убрать ненужные товары из корзины чтобы хватило монет.");
- basket.ShowProducts();
- basket.RemoveProductInBascet();
- productsAllPrice = basket.AllPrice();
- }
- else
- {
- Console.WriteLine("Довольный покупатель уходит со своими товарами.");
- isBuy = false;
- }
- Console.ReadKey();
- }
- }
- }
- class Basket
- {
- Random random = new Random();
- private int _productsAllPrice = 0;
- private List<Product> _productsInBasket = new List<Product>();
- public void TakeProducts(Product product)
- {
- _productsInBasket.Add(product);
- }
- public int AllPrice()
- {
- _productsAllPrice = 0;
- foreach (Product product in _productsInBasket)
- {
- _productsAllPrice += product.Price;
- }
- return _productsAllPrice;
- }
- public void ShowProducts()
- {
- foreach (Product product in _productsInBasket)
- {
- Console.WriteLine($"{product.Name}");
- }
- }
- public void RemoveProductInBascet()
- {
- Product product = null;
- int randomIndex = random.Next(_productsInBasket.Count);
- product = _productsInBasket[randomIndex];
- _productsInBasket.Remove(product);
- }
- }
- class Buyer
- {
- public Buyer(int money)
- {
- Money = money;
- }
- public int Money { get; private set; }
- }
- class Product
- {
- public Product(string name, int price)
- {
- Name = name;
- Price = price;
- }
- public string Name { get; private set; }
- public int Price { get; private set; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement