Advertisement
TwinFrame

Shop question

Feb 2nd, 2020
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Clight_25_OOP_Shop
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. int numProductsInRow = 4;
  10.  
  11. Product tomato = new Product("Помидоры", 15, 250);
  12. Product cucumber = new Product("Огурцы", 15, 200);
  13. Product potato = new Product("Картофель", 20, 100);
  14. Product orange = new Product("Апельсин", 7, 350);
  15. Product aplle = new Product("Яблоки", 13, 150);
  16.  
  17. Shop vegetableShop = new Shop("Овощной", new Product[] { tomato, cucumber, potato, orange, aplle }, 0);
  18.  
  19. //string name = SetName();
  20. string name = "Покупатель";
  21. Buyer buyer = new Buyer(name, new Product[0], 1000);
  22.  
  23. vegetableShop.ShowProducts();
  24. buyer.ShowProducts();
  25.  
  26.  
  27. string SetName()
  28. {
  29. Console.WriteLine($"Добро пожаловать в магазин \"{vegetableShop.GetName()}\"");
  30. Console.Write("\nВведите свое имя: ");
  31. string name = Console.ReadLine();
  32. Console.Clear();
  33. return name;
  34. }
  35. }
  36. }
  37.  
  38. interface IShoping
  39. {
  40. void DoShoping();
  41. }
  42.  
  43. class Dealer
  44. {
  45. protected string _name;
  46. protected Product[] _products;
  47.  
  48. public Dealer(string name, Product[] products)
  49. {
  50. _name = name;
  51. _products = products;
  52. }
  53.  
  54. public void ShowProducts()
  55. {
  56. for (int i = 0; i < _products.Length; i++)
  57. {
  58. Console.Write((i + 1) + " ");
  59. _products[i].ShowProduct();
  60. Console.WriteLine("\n");
  61. }
  62. }
  63.  
  64. public string GetName()
  65. {
  66. return _name;
  67. }
  68. public int GetLenghtProducts()
  69. {
  70. return _products.Length;
  71. }
  72. }
  73. class Shop : Dealer
  74. {
  75. protected int _income;
  76.  
  77. public Shop(string name, Product[] products, int income) : base(name, products)
  78. {
  79. _income = income;
  80. }
  81. }
  82.  
  83. class Buyer : Dealer, IShoping
  84. {
  85. protected int _wallet;
  86.  
  87. public Buyer(string name, Product[] products, int wallet) : base(name, products)
  88. {
  89. _wallet = wallet;
  90. }
  91.  
  92. public void DoShoping()
  93. {
  94. for (int i = 0; i < GetLenghtProducts(); i++)
  95. {
  96. products[i];
  97. }
  98. }
  99. }
  100.  
  101. class Product
  102. {
  103. protected string _name;
  104. protected int _price;
  105. protected int _quantity;
  106.  
  107. public Product(string name, int quantity, int price)
  108. {
  109. _name = name;
  110. _price = price;
  111. _quantity = quantity;
  112. }
  113.  
  114. public void ShowProduct()
  115. {
  116. Console.Write($"{_name}\nКол-во: {_quantity} кг\nЦена: {_price} руб.");
  117. }
  118. }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement