Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Threading;
- public class Program
- {
- public static void Main()
- {
- int timeSleep = 700;
- Shop shop = new Shop();
- while (shop.IsOver() != true)
- {
- shop.Update();
- Thread.Sleep(timeSleep);
- }
- }
- }
- public class Shop
- {
- private Customer _customer;
- private Random _random;
- private int _amountClients;
- private int _amountMoneyCashBox;
- private int _amountItemsMinimum = 5;
- private int _amountItemsMaximum = 20;
- private int _priceItemMinimum = 10;
- private int _priceItemMaximum = 400;
- private int _walletCustomerMinimum = 100;
- private int _walletCustomerMaximum = 2500;
- private int _amountClientsMinimum = 10;
- private int _amountClientsMaximum = 100;
- private string[] _namesItems =
- {
- "Milk", "Bread", "Sausages",
- "Cheese", "Butter", "Chocolate nuts"
- };
- public Shop()
- {
- _random = new Random();
- _amountMoneyCashBox = 0;
- _amountClients = _random.Next(_amountClientsMinimum, _amountClientsMaximum);
- CreateCustomer();
- }
- public void Update()
- {
- PrintCustomers();
- TryTrade();
- }
- public void PrintCustomers()
- {
- Console.Clear();
- Console.WriteLine("Customers stay in order : " + _amountClients);
- Console.WriteLine("Money in cashbox : " + _amountMoneyCashBox);
- Console.WriteLine(_customer);
- }
- public void TryTrade()
- {
- if (_customer.PriceTotalItemes <= _customer.Wallet)
- {
- Console.WriteLine("Client bought items");
- _amountMoneyCashBox += _customer.PriceTotalItemes;
- CreateCustomer();
- }
- else
- {
- if (_customer.IsEmptyItems())
- {
- Console.WriteLine("Customer haven't items to buy.");
- CreateCustomer();
- }
- else
- {
- Console.WriteLine("Customer haven't enought money.");
- int indexItem = _random.Next(0, _customer.AmountItems);
- _customer.RemoveItem(indexItem);
- }
- }
- }
- public bool IsOver()
- {
- return _amountClients < 0;
- }
- private void CreateCustomer()
- {
- --_amountClients;
- int amountItems = _random.Next(_amountItemsMinimum, _amountItemsMaximum);
- int wallet = _random.Next(_walletCustomerMinimum, _walletCustomerMaximum);
- _customer = new Customer(wallet);
- string name;
- int price;
- Item item;
- for (int i = 0; i < amountItems; ++i)
- {
- name = _namesItems[_random.Next(0, _namesItems.Length)];
- price = _random.Next(_priceItemMinimum, _priceItemMaximum);
- item = new Item(name, price);
- _customer.AddItem(item);
- }
- }
- }
- public class Customer
- {
- private List<Item> _items;
- public int Wallet { get; private set; }
- public int PriceTotalItemes { get; private set; }
- public int AmountItems => _items.Count;
- public Customer(int wallet)
- {
- Wallet = wallet;
- _items = new List<Item>();
- }
- public override string ToString()
- {
- string result = "";
- result += "Wallet : " + Wallet + " \n";
- result += "Total price of items : " + PriceTotalItemes + " \n";
- for (int i = 0; i < _items.Count; ++i)
- result += String.Format("{0}. {1} \n", i, _items[i]);
- return result;
- }
- public void AddItem(Item item)
- {
- _items.Add(item);
- PriceTotalItemes += item.Price;
- }
- public void RemoveItem(int index)
- {
- PriceTotalItemes -= _items[index].Price;
- _items.RemoveAt(index);
- }
- public bool IsEmptyItems()
- {
- return _items.Count <= 0;
- }
- }
- public class Item
- {
- public string Name { get; private set; }
- public int Price { get; private set; }
- public Item(string name, int price)
- {
- Name = name;
- Price = price;
- }
- public Item(Item item)
- {
- Name = item.Name;
- Price = item.Price;
- }
- public override string ToString()
- {
- return String.Format("{0} - {1:0.00} ", Name, Price);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment