Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Diagnostics;
- using System.Xml.Linq;
- namespace Супермаркет
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- Supermarket supermarket = new Supermarket();
- supermarket.Work();
- }
- }
- class Supermarket
- {
- private Client _client = new Client();
- private List<Product> _products = new List<Product>();
- private List<Product> _clientBasket = new List<Product>();
- private int _purchaseAmount;
- private int _quantityClients;
- public Supermarket()
- {
- _clientBasket = _client.ReturnClientBasket();
- _products.Add(new Product(0, "Пакет", 10));
- _products.Add(new Product(1, "Бананы", 85));
- _products.Add(new Product(2, "Молоко", 65));
- _products.Add(new Product(3, "Пиво", 50));
- _products.Add(new Product(4, "Курица", 320));
- _products.Add(new Product(5, "Сосиски", 125));
- _products.Add(new Product(6, "Кола", 75));
- }
- public void Work()
- {
- Console.WriteLine("Введите количество посетителей:");
- _quantityClients = Utility.ReturnInputNumber();
- for (int i = 0; i < _quantityClients; i++)
- {
- FillBasket();
- CanPay();
- Console.ForegroundColor = ConsoleColor.DarkYellow;
- Console.WriteLine("\nНажмите любую клавишу для вызова следующего клиента");
- Console.ForegroundColor = ConsoleColor.White;
- Console.ReadKey();
- Console.Clear();
- _purchaseAmount = 0;
- _client = new Client();
- }
- }
- private void CanPay()
- {
- while (_client.Money < _purchaseAmount)
- {
- Console.ForegroundColor = ConsoleColor.DarkGreen;
- Console.Write($"\nСумма покупки: {_purchaseAmount}");
- Console.ForegroundColor = ConsoleColor.White;
- Console.ForegroundColor = ConsoleColor.DarkYellow;
- Console.Write($"\nДеньги покупателя: {_client.Money}\n");
- Console.ForegroundColor = ConsoleColor.White;
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("Денег не хватает, Галя! Отмена!");
- Console.ForegroundColor = ConsoleColor.White;
- RemoveProduct();
- }
- if (_clientBasket.Count == 0)
- {
- Console.ForegroundColor = ConsoleColor.DarkRed;
- Console.WriteLine("\nЖалобную книгу мне! (Клиент передумал покупать в этом магазине)");
- Console.ForegroundColor = ConsoleColor.White;
- return;
- }
- Console.ForegroundColor = ConsoleColor.Yellow;
- Console.Write($"\nСумма покупки: {_purchaseAmount}");
- Console.ForegroundColor = ConsoleColor.White;
- Console.ForegroundColor = ConsoleColor.DarkYellow;
- Console.Write($"\nДеньги покупателя: {_client.Money}");
- Console.ForegroundColor = ConsoleColor.White;
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("\nДенег хватает\n");
- Console.ForegroundColor = ConsoleColor.White;
- Console.ForegroundColor = ConsoleColor.DarkCyan;
- Console.WriteLine("Купленные товары:\n");
- Console.ForegroundColor = ConsoleColor.White;
- ShowProductBasket();
- }
- private void RemoveProduct()
- {
- int minRandomNumber = 0;
- int randomProduct = Utility.GenerateRandomNumber(minRandomNumber, _clientBasket.Count);
- Console.Write("Удаленный товар: ");
- ShowProduct(randomProduct);
- _purchaseAmount -= _clientBasket[randomProduct].Price;
- _clientBasket.RemoveAt(randomProduct);
- }
- private void ShowProduct(int foundProduct)
- {
- Console.WriteLine($"ID: {_clientBasket[foundProduct].Id} Название: {_clientBasket[foundProduct].Title} Цена: {_clientBasket[foundProduct].Price} Руб.");
- }
- private void ShowProductBasket()
- {
- for (int i = 0; i < _clientBasket.Count; i++)
- {
- Console.WriteLine($"ID: {_clientBasket[i].Id} Название: {_clientBasket[i].Title} Цена: {_clientBasket[i].Price} Руб.");
- }
- }
- private void FillBasket()
- {
- int minQuantityPurchases = 2;
- int maxQuantityPurchases = 10;
- int minNumberIDProduct = 0;
- int quantityPurchases = Utility.GenerateRandomNumber(minQuantityPurchases, maxQuantityPurchases);
- _clientBasket = new List<Product>(quantityPurchases);
- for (int i = 0; i < quantityPurchases; i++)
- {
- int randomProduct = Utility.GenerateRandomNumber(minNumberIDProduct, _products.Count);
- _clientBasket.Add(_products[randomProduct]);
- _purchaseAmount += _products[randomProduct].Price;
- ShowProduct(i);
- }
- }
- }
- class Client
- {
- private int minCashInPocket = 100;
- private int maxCashInPocket = 1200;
- private List<Product> _clientBasket = new List<Product>();
- public Client()
- {
- Money = Utility.GenerateRandomNumber(minCashInPocket, maxCashInPocket);
- }
- public int Money { get; private set; }
- public List<Product> ReturnClientBasket()
- {
- return _clientBasket;
- }
- }
- class Product
- {
- public Product(int id, string name, int price)
- {
- Id = id;
- Title = name;
- Price = price;
- }
- public int Id { get; private set; }
- public string Title { get; private set; }
- public int Price { get; private set; }
- }
- class Utility
- {
- private static Random _random = new Random();
- public static int GenerateRandomNumber(int min, int max)
- {
- int randomNumber = _random.Next(min, max);
- return randomNumber;
- }
- public static int ReturnInputNumber()
- {
- int number;
- while (int.TryParse(Console.ReadLine(), out number) == false)
- {
- Console.WriteLine("Введено не число, попробуйте еще раз: ");
- }
- return number;
- }
- }
- }
Add Comment
Please, Sign In to add comment