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 CSLight
- {
- class Program
- {
- static void Main(string[] args)
- {
- Supermarket supermarket = new Supermarket();
- supermarket.Work();
- }
- }
- class Supermarket
- {
- private Queue<Client> _clients = new Queue<Client>();
- private int _money = 0;
- public Supermarket()
- {
- Random random = new Random();
- for (int i = 0; i < random.Next(10, 15); i++)
- {
- _clients.Enqueue(new Client(random));
- }
- }
- public void Work()
- {
- while (_clients.Count > 0)
- {
- Console.WriteLine($"У вас в очереди {_clients.Count} клиентов, а в кассе {_money} монет. Нажмите любую клавишу, чтобы принять клиента");
- Console.ReadKey();
- Client client = _clients.Dequeue();
- Console.WriteLine($"Подошел клиент с {client.GetBasketSize()} товарами");
- while (!client.CheckSolvency())
- {
- Console.WriteLine($"Вы пробили все товары на сумму {client.CalculateCost()} монет, но у клиента не хватает денег. Нажмите любую клавишу, чтобы попросить клиента выложить любой товар");
- Console.ReadKey();
- client.RefuseProduct();
- Console.WriteLine($"У клиента осталось {client.GetBasketSize()} товаров");
- }
- int money = client.ToPay();
- _money += money;
- Console.WriteLine($"Клиент оплатил все товары. Вы получили {money} монет. Нажмите любую клавишу, чтобы выдать чек и попрощаться");
- Console.ReadKey();
- Console.Clear();
- }
- }
- }
- class Client
- {
- private List<Product> _products = new List<Product>();
- private int _money;
- private int _totalCost;
- private Random _random;
- public Client(Random random)
- {
- _random = random;
- _money = _random.Next(500, 1000);
- for (int i = 0; i < _random.Next(5, 10); i++)
- {
- _products.Add(new Product(_random));
- }
- }
- public int CalculateCost()
- {
- _totalCost = 0;
- for (int i = 0; i < _products.Count; i++)
- {
- _totalCost += _products[i].Cost;
- }
- return _totalCost;
- }
- public bool CheckSolvency()
- {
- CalculateCost();
- if (_totalCost <= _money)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public int ToPay()
- {
- _money -= _totalCost;
- return _totalCost;
- }
- public void RefuseProduct()
- {
- int randomNumber = _random.Next(0, _products.Count);
- _products.RemoveAt(randomNumber);
- }
- public int GetBasketSize()
- {
- return _products.Count;
- }
- }
- class Product
- {
- public int Cost { get; private set; }
- public Product(Random random)
- {
- Cost = random.Next(100, 200);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement