Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Clight_25_OOP_Shop
- {
- class Program
- {
- static void Main(string[] args)
- {
- int numProductsInRow = 4;
- Product tomato = new Product("Помидоры", 15, 250);
- Product cucumber = new Product("Огурцы", 15, 200);
- Product potato = new Product("Картофель", 20, 100);
- Product orange = new Product("Апельсин", 7, 350);
- Product aplle = new Product("Яблоки", 13, 150);
- Shop vegetableShop = new Shop("Овощной", new Product[] { tomato, cucumber, potato, orange, aplle }, 0);
- //string name = SetName();
- string name = "Покупатель";
- Buyer buyer = new Buyer(name, new Product[0], 1000);
- vegetableShop.ShowProducts();
- buyer.ShowProducts();
- string SetName()
- {
- Console.WriteLine($"Добро пожаловать в магазин \"{vegetableShop.GetName()}\"");
- Console.Write("\nВведите свое имя: ");
- string name = Console.ReadLine();
- Console.Clear();
- return name;
- }
- }
- }
- interface IShoping
- {
- void DoShoping();
- }
- class Dealer
- {
- protected string _name;
- protected Product[] _products;
- public Dealer(string name, Product[] products)
- {
- _name = name;
- _products = products;
- }
- public void ShowProducts()
- {
- for (int i = 0; i < _products.Length; i++)
- {
- Console.Write((i + 1) + " ");
- _products[i].ShowProduct();
- Console.WriteLine("\n");
- }
- }
- public string GetName()
- {
- return _name;
- }
- public int GetLenghtProducts()
- {
- return _products.Length;
- }
- }
- class Shop : Dealer
- {
- protected int _income;
- public Shop(string name, Product[] products, int income) : base(name, products)
- {
- _income = income;
- }
- }
- class Buyer : Dealer, IShoping
- {
- protected int _wallet;
- public Buyer(string name, Product[] products, int wallet) : base(name, products)
- {
- _wallet = wallet;
- }
- public void DoShoping()
- {
- for (int i = 0; i < GetLenghtProducts(); i++)
- {
- products[i];
- }
- }
- }
- class Product
- {
- protected string _name;
- protected int _price;
- protected int _quantity;
- public Product(string name, int quantity, int price)
- {
- _name = name;
- _price = price;
- _quantity = quantity;
- }
- public void ShowProduct()
- {
- Console.Write($"{_name}\nКол-во: {_quantity} кг\nЦена: {_price} руб.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement