Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel.Design;
- using System.Data;
- using System.Globalization;
- using System.IO;
- using System.Reflection.Metadata;
- namespace ConsoleApp3
- {
- class Program
- {
- static void Main(string[] args)
- {
- Buyer buyer = new Buyer();
- Seller seller = new Seller();
- while (true)
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.SetCursorPosition(45, 0);
- Console.WriteLine(buyer.ShowCash());
- Console.SetCursorPosition(0, 0);
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine("<<<Добро пожаловать в магазин>>>");
- Console.WriteLine("Нажмите 1 что бы посмотреть список доступных для покупки товаров");
- Console.WriteLine("Нажмите 2 что бы купить товар");
- Console.WriteLine("Нажмите 3 что бы посмотреть инвентарь");
- Console.WriteLine("Нажмите 4 что бы узнать кассу в магазине\n");
- Console.Write("Выберите функцию: ");
- switch (Convert.ToInt32(Console.ReadLine()))
- {
- case 1:
- seller.ShowProducts();
- break;
- case 2:
- Console.Write("Напишите название товара: ");
- string value = Console.ReadLine();
- if(buyer.CheckSolvency(seller, value))
- {
- buyer.InventoryAdds(seller.SellProduct(value, buyer.Pay()));
- }
- else
- {
- Console.WriteLine("Недостаточно денег");
- }
- break;
- case 3:
- buyer.ShowInventory();
- break;
- case 4:
- seller.ShowCash();
- break;
- default:
- Console.WriteLine("Вы ввели неверную функцию, повторите попытку...");
- break;
- }
- Console.ReadLine();
- Console.Clear();
- }
- }
- }
- class Buyer
- {
- Seller seller;
- private List<Product> _inventory = new List<Product>();
- private int _money;
- private int _moneyToPay;
- public Buyer()
- {
- Random rnd = new Random();
- _money = rnd.Next(1000, 1500);
- }
- public int ShowCash()
- {
- return _money;
- }
- public bool CheckSolvency(Seller seller, string product)
- {
- _moneyToPay = seller.ShowPrice(product);
- if (_money >= _moneyToPay)
- {
- return true;
- }
- else
- {
- _moneyToPay = 0;
- return false;
- }
- }
- public int Pay()
- {
- _money -= _moneyToPay;
- return _moneyToPay;
- }
- public void InventoryAdds(Product item)
- {
- _inventory.Add(item);
- }
- public void ShowInventory()
- {
- foreach (var item in _inventory)
- {
- Console.WriteLine(item._product);
- }
- }
- }
- class Seller
- {
- private Dictionary<string, Product> _products = new Dictionary<string, Product>
- {
- { "Молоко", new Product("Молоко", 50) },
- { "Сигареты", new Product("Сигареты", 50) },
- { "Сахар", new Product("Сахар", 50) },
- { "Соль", new Product("Соль", 50) }
- };
- private int _money;
- public void ShowCash()
- {
- Console.WriteLine("Касса продуктового магазина - " + _money);
- }
- public int ShowPrice(string product)
- {
- return _products[product]._priсe;
- }
- public void ShowProducts()
- {
- foreach (var product in _products)
- {
- Console.WriteLine($"{product.Value._priсe} - {product.Value._product}");
- }
- }
- public Product SellProduct(string product, int moneyToPay)
- {
- _money += moneyToPay;
- var value = _products[product];
- _products.Remove(product);
- return value;
- }
- }
- class Product
- {
- public string _product { get; private set; }
- public int _priсe { get; private set; }
- public Product(string product, int priсe)
- {
- _product = product;
- _priсe = priсe;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement