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 Shop
- {
- class Program
- {
- static void Main(string[] args)
- {
- Shop shop = new Shop();
- shop.ShowCustomersInfo();
- Console.WriteLine();
- shop.Work();
- Console.ReadKey();
- }
- }
- class Product
- {
- public string Name { get; private set; }
- public int Price { get; private set; }
- public Product(string name, int price)
- {
- Name = name;
- Price = price;
- }
- }
- class Customer
- {
- private List<Product> _products = new List<Product>();
- public int Cash { get; private set; }
- public Customer(int cash)
- {
- Fill();
- Cash = cash;
- }
- public int GetPrice()
- {
- int finalPrice = 0;
- foreach (Product product in _products)
- {
- finalPrice += product.Price;
- }
- return finalPrice;
- }
- public void RemoveProduct()
- {
- Random random = new Random();
- int productIndex;
- productIndex = random.Next(0, _products.Count);
- _products.RemoveAt(productIndex);
- }
- public void ShowInfo()
- {
- foreach (Product product in _products)
- {
- Console.WriteLine($"{product.Name} | Price - {product.Price}");
- }
- }
- public void BuyProducts(int price)
- {
- Cash -= price;
- }
- private void Fill()
- {
- _products.Add(new Product("Milk", 15));
- _products.Add(new Product("Eggs", 25));
- _products.Add(new Product("Meat", 40));
- _products.Add(new Product("Fish", 30));
- _products.Add(new Product("Sushi", 17));
- _products.Add(new Product("Bread", 27));
- }
- }
- class Shop
- {
- private List<Customer> _customers = new List<Customer>();
- public Shop()
- {
- CreateQueue(5);
- }
- private void CreateQueue(int quantity)
- {
- Random random = new Random();
- for (int i = 0; i < quantity; i++)
- {
- _customers.Add(new Customer(random.Next(100,200)));
- }
- Console.WriteLine($"Очередь из {quantity} человек");
- }
- public void ShowCustomersInfo()
- {
- for (int i = 0; i < _customers.Count; i++)
- {
- Console.WriteLine($"\n{i + 1} клиент. Cash - {_customers[i].Cash}");
- _customers[i].ShowInfo();
- }
- Console.WriteLine("\nДля старта кассы нажмите любую кнопку...");
- Console.ReadLine();
- }
- public void Work()
- {
- Console.WriteLine();
- int counter = 1;
- foreach (Customer customer in _customers)
- {
- Console.Clear();
- Console.WriteLine($"{counter} клиент. Кол-во cash - {customer.Cash}");
- counter++;
- while (customer.Cash < customer.GetPrice())
- {
- customer.RemoveProduct();
- }
- Console.WriteLine($"Список покупок на сумму {customer.GetPrice()}:");
- customer.BuyProducts(customer.GetPrice());
- customer.ShowInfo();
- Console.WriteLine($"Остаток на счёте: {customer.Cash}");
- Console.WriteLine("\nДля следующего покупателя нажмите любую кнопку...");
- Console.ReadLine();
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment