Advertisement
dmitryEfremov

Untitled

Aug 7th, 2020
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel.Design;
  4. using System.Globalization;
  5. using System.IO;
  6.  
  7. namespace ConsoleApp3
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. Buyer buyer = new Buyer();
  14. Seller seller = new Seller();
  15. while (true)
  16. {
  17. Console.ForegroundColor = ConsoleColor.Green;
  18. Console.SetCursorPosition(45, 0);
  19. Console.WriteLine(buyer.ShowCash());
  20. Console.SetCursorPosition(0, 0);
  21. Console.ForegroundColor = ConsoleColor.White;
  22. Console.WriteLine("<<<Добро пожаловать в магазин>>>");
  23. Console.WriteLine("Нажмите 1 что бы посмотреть список доступных для покупки товаров");
  24. Console.WriteLine("Нажмите 2 что бы купить товар");
  25. Console.WriteLine("Нажмите 3 что бы посмотреть инвентарь");
  26. Console.WriteLine("Нажмите 4 что бы узнать кассу в магазине\n");
  27. Console.Write("Выберите функцию: ");
  28. switch (Convert.ToInt32(Console.ReadLine()))
  29. {
  30. case 1:
  31. seller.ShowProducts();
  32. break;
  33. case 2:
  34. Console.Write("Напишите название товара: ");
  35. buyer.BuyProduct( seller , Console.ReadLine());
  36. break;
  37. case 3:
  38. buyer.ShowInventory();
  39. break;
  40. case 4:
  41. seller.ShowCash();
  42. break;
  43. default:
  44. Console.WriteLine("Вы ввели неверную функцию, повторите попытку...");
  45. break;
  46. }
  47. Console.ReadLine();
  48. Console.Clear();
  49. }
  50. }
  51. }
  52.  
  53. class Buyer
  54. {
  55. private List<string> _inventory = new List<string>();
  56. private int _money;
  57.  
  58. public Buyer()
  59. {
  60. Random rnd = new Random();
  61. _money = rnd.Next(1000, 1500);
  62. }
  63.  
  64. public int ShowCash()
  65. {
  66. return _money;
  67. }
  68.  
  69. public void BuyProduct(Seller seller, string product)
  70. {
  71. if(_money >= seller.ShowPrice(product))
  72. {
  73. _money -= seller.ShowPrice(product);
  74. seller.GiveProduct(product);
  75. _inventory.Add(product);
  76. }
  77. else
  78. Console.WriteLine("У вас недостаточно денег");
  79. }
  80.  
  81. public void ShowInventory()
  82. {
  83. foreach (var item in _inventory)
  84. {
  85. Console.WriteLine(item);
  86. }
  87. }
  88. }
  89.  
  90. class Seller : Product
  91. {
  92. private int _money;
  93.  
  94. public void ShowCash()
  95. {
  96. Console.WriteLine("Касса продуктового магазина - " + _money);
  97. }
  98.  
  99. public int ShowPrice(string product)
  100. {
  101. return _products[product];
  102. }
  103.  
  104. public void ShowProducts()
  105. {
  106. foreach (var product in _products)
  107. {
  108. Console.WriteLine($"{product.Key} - {product.Value}");
  109. }
  110. }
  111.  
  112. public void GiveProduct(string product)
  113. {
  114. _money += ShowPrice(product);
  115. _products.Remove(product);
  116. }
  117. }
  118.  
  119. class Product
  120. {
  121. protected Dictionary<string, int> _products = new Dictionary<string, int>()
  122. {
  123. {"Молоко", 50 },
  124. {"Сигареты", 200 },
  125. {"Энергетик", 30 }
  126. };
  127. }
  128. }
  129.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement