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 _3._3
- {
- class Program
- {
- static void Main(string[] args)
- {
- Product[] sellerProducts = { new Product("Яблоко", 3, 15), new Product("Молоко", 6, 15), new Product("Хлеб", 5, 15), new Product("Пиво", 15, 15), new Product("Колбаса", 20, 15) };
- Product[] customerProducts = { new Product("Сигареты", 5)};
- Seller seller = new Seller(sellerProducts);
- Customer customer = new Customer(1000, customerProducts);
- bool mainMenu = true, sellerMenu, customerMenu;
- while (mainMenu == true)
- {
- Console.Clear();
- Console.WriteLine("Главное меню");
- Console.WriteLine("\n1. Продавец\n2. Покупатель\n3. Выход");
- Console.Write("\nВаш выбор: ");
- switch (Convert.ToInt32(Console.ReadLine()))
- {
- case 1:
- sellerMenu = true;
- while (sellerMenu == true)
- {
- Console.Clear();
- Console.WriteLine("Меню продавца");
- Console.WriteLine("\n1. Показать товар\n2. Заполнить склад\n3. Назад");
- Console.Write("\nВаш выбор: ");
- switch (Convert.ToInt32(Console.ReadLine()))
- {
- case 1:
- Console.Clear();
- Console.WriteLine("У вас на витрине: ");
- seller.ShowAvailability();
- Console.ReadKey();
- break;
- case 2:
- seller.FillShelf();
- ConsoleMessage("Витрины заполнены");
- Console.ReadKey();
- break;
- case 3:
- sellerMenu = false;
- break;
- default:
- ConsoleMessage("Такой пункт меню отсутствует");
- break;
- }
- }
- break;
- case 2:
- customerMenu = true;
- while (customerMenu == true)
- {
- Console.Clear();
- Console.WriteLine("Меню покупателя");
- Console.WriteLine("\nУ вас в кошельке: " + customer.Money + " монет");
- Console.WriteLine("\n1. Купить товар\n2. Показать содержимое пакета\n3. Назад");
- Console.Write("\nВаш выбор: ");
- switch (Convert.ToInt32(Console.ReadLine()))
- {
- case 1:
- Console.Clear();
- Console.WriteLine("На витрине: ");
- seller.ShowAvailability();
- Console.Write("Название покупаемого продукта: ");
- string uiName = Console.ReadLine();
- Console.Write("Количество: ");
- int uiCount = Convert.ToInt32(Console.ReadLine());
- customer.BuyProduct(sellerProducts, uiName, uiCount);
- Console.ReadKey();
- break;
- case 2:
- Console.Clear();
- Console.WriteLine("У вас в пакете: ");
- customer.ShowAvailability();
- Console.ReadKey();
- break;
- case 3:
- customerMenu = false;
- break;
- default:
- ConsoleMessage("Такой пункт меню отсутствует");
- break;
- }
- }
- break;
- case 3:
- mainMenu = false;
- break;
- default:
- ConsoleMessage("Такой пункт меню отсутствует");
- break;
- }
- }
- }
- static void ConsoleMessage(string message)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine(message);
- Console.ResetColor();
- Console.ReadKey();
- }
- }
- class Product
- {
- public string Name;
- public int Price;
- public int Count;
- public int CountOnPackage;
- public Product(string name, int price, int count)
- {
- Name = name;
- Price = price;
- Count = count;
- }
- public Product(string name, int countOnPackage)
- {
- Name = name;
- CountOnPackage = countOnPackage;
- }
- }
- class Seller
- {
- public Product[] ProductsOnShelf;
- public Seller(Product[] productsOnShelf)
- {
- ProductsOnShelf = productsOnShelf;
- }
- public void FillShelf()
- {
- foreach(Product product in ProductsOnShelf)
- {
- product.Count = 15;
- }
- }
- public void ShowAvailability()
- {
- foreach(Product product in ProductsOnShelf)
- {
- Console.WriteLine("\n" + product.Name + " - " + product.Price + " монет" + "\nКоличество: " + product.Count + " штук");
- Console.WriteLine("=============================");
- }
- }
- }
- class Customer
- {
- public int Money;
- public Product[] ProductsOnPackage;
- public Customer(int money, Product[] productsOnPackage)
- {
- Money = money;
- ProductsOnPackage = productsOnPackage;
- }
- public void BuyProduct(Product[] sellerProducts, string product, int countProd)
- {
- for(int i = 0; i < sellerProducts.Length; i++)
- {
- if(product == sellerProducts[i].Name && countProd <= sellerProducts[i].Count && Money >= (sellerProducts[i].Price * countProd))
- {
- for (int j = 0; j < sellerProducts.Length; j++)
- {
- if (product == sellerProducts[j].Name)
- {
- Money -= (sellerProducts[j].Price * countProd);
- sellerProducts[j].Count -= countProd;
- }
- }
- Product newProduct = new Product(product, countProd);
- Product[] tempBuyProducts = new Product[ProductsOnPackage.Length + 1];
- for (int j = 0; j < ProductsOnPackage.Length; j++)
- {
- tempBuyProducts[j] = ProductsOnPackage[j];
- }
- tempBuyProducts[tempBuyProducts.Length - 1] = newProduct;
- ProductsOnPackage = tempBuyProducts;
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("\nПокупка прошла успешно");
- Console.ResetColor();
- }
- else if(product == sellerProducts[i].Name && countProd > sellerProducts[i].Count)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("\nНедостаточно продуктов");
- Console.ResetColor();
- }
- else if (product == sellerProducts[i].Name && Money < (sellerProducts[i].Price * countProd))
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("\nНедостаточно монет");
- Console.ResetColor();
- }
- }
- }
- public void ShowAvailability()
- {
- foreach (Product product in ProductsOnPackage)
- {
- Console.WriteLine("\n" + product.Name + " - " + product.CountOnPackage + " штук");
- Console.WriteLine("=============================");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment