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)
- {
- Supermarket supermarket = new Supermarket();
- supermarket.Work();
- }
- }
- class Supermarket
- {
- private int _money;
- private Queue<Buyer> _buyers = new Queue<Buyer>();
- public Supermarket()
- {
- int countBuyers = 10;
- for (int i = 0; i < countBuyers; i++)
- {
- _buyers.Enqueue(new Buyer());
- }
- }
- public void Work()
- {
- while(_buyers.Count > 0)
- {
- ShowInfo();
- _money += _buyers.Dequeue().BuyProducts();
- Console.ReadKey();
- }
- Console.Write($"Магазин заработал за сегодня = {_money}$");
- }
- private void ShowInfo()
- {
- Console.Clear();
- Console.WriteLine($"Итого магазин заработал = {_money}$\nКлиентов в очереди: {_buyers.Count}\nНажмите любую клавишу, чтобы обслужить клиента");
- Console.ReadKey();
- }
- }
- class Buyer
- {
- private int _money;
- private List<Product> _cart = new List<Product>();
- public Buyer()
- {
- Random random = new Random();
- int minMoney = 400;
- int maxMoney = 1500;
- _money = random.Next(minMoney, maxMoney);
- int minCountProducts = 4;
- int maxCountProducts = 12;
- int countProducts = random.Next(minCountProducts, maxCountProducts);
- for (int i = 0; i < countProducts; i++)
- {
- _cart.Add(new Product());
- }
- }
- public int BuyProducts()
- {
- bool isBuy = true;
- while (isBuy)
- {
- Console.Clear();
- Console.WriteLine($"У клиента = {_money}$\nУ клиента: {_cart.Count} штук товара, на сумму {Sum()}$");
- Console.ReadKey();
- if (_money >= Sum())
- {
- Console.WriteLine($"У покупателя достаточно денег, магазин заработал {Sum()}$");
- return Sum();
- }
- else
- {
- Console.WriteLine("У покупателя недостаточно денег, 1 товар был убран их корзины!");
- RemoveProduct();
- }
- Console.ReadKey();
- }
- return 0;
- }
- private void RemoveProduct()
- {
- Random random = new Random();
- int randomIndex = random.Next(0, _cart.Count);
- _cart.RemoveAt(randomIndex);
- }
- private int Sum()
- {
- int sum = 0;
- for (int i = 0; i < _cart.Count; i++)
- {
- sum += _cart[i].Price;
- }
- return sum;
- }
- }
- class Product
- {
- public int Price { get; private set; }
- public Product()
- {
- Random random = new Random();
- int minPrise = 50;
- int maxPrise = 201;
- Price = random.Next(minPrise, maxPrise);
- }
- }
- }
Add Comment
Please, Sign In to add comment