Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace Zamestitel
- {
- public interface ICustomer
- {
- void Request();
- }
- class RealCustomer : ICustomer
- {
- private string firstname = "Denis";
- private string lastname = "Smirnov";
- private int age = 20;
- public string[] ShopList = new string[5] { "car", "bread", "milk", "moto", "lemon" };
- Queue<string> ShopBasket = new Queue<string>();
- private void AddToShopBasket()
- {
- string product = Console.ReadLine();
- while (product != "stop")
- {
- ShopBasket.Enqueue(product);
- product = Console.ReadLine();
- }
- }
- private void ShowShopBasket()
- {
- foreach( string list in ShopBasket)
- {
- Console.WriteLine(list);
- }
- }
- public void Request()
- {
- Console.WriteLine("1.Добавить в корзину товары");
- Console.WriteLine("2.Посмотреть корзину");
- Console.WriteLine("3.Личный кабинет");
- Console.WriteLine("4.Выйти");
- int number = Convert.ToInt32(Console.ReadLine());
- if (number == 1)
- {
- Console.WriteLine("Введите название товаров, которые вы хотите добавить в корзину(Для отмены введите stop)");
- AddToShopBasket();
- this.Request();
- }
- else if (number == 2)
- {
- Console.WriteLine("В корзине: ");
- ShowShopBasket();
- this.Request();
- }
- else if(number == 3)
- {
- Console.WriteLine(firstname);
- Console.WriteLine(lastname);
- Console.WriteLine(age);
- this.Request();
- }
- else if(number == 4)
- {
- Environment.Exit(0);
- }
- }
- }
- class ProxyCustomer : ICustomer
- {
- private RealCustomer _realCustomer;
- public string password = "test";
- public string[] ShopList = new string[5] { "car", "bread", "milk", "moto", "lemon" };
- private void ShowShopList()
- {
- for(int i = 0; i < 5; i++)
- {
- Console.WriteLine(ShopList[i]);
- }
- }
- private void Authenticate(string passwd)
- {
- if (password == passwd)
- {
- Console.WriteLine("Вы успешно зашли");
- this._realCustomer = new RealCustomer();
- }
- else Console.WriteLine("Повторите попытку");
- }
- public void Request()
- {
- if(this.CheckAcces())
- {
- this._realCustomer.Request();
- }
- else
- {
- Console.WriteLine("1.Посмотреть список товаров");
- Console.WriteLine("2.Авторизоваться");
- int number = Convert.ToInt32(Console.ReadLine());
- if(number == 1)
- {
- ShowShopList();
- Request();
- }
- if(number == 2)
- {
- Console.WriteLine("Введите пароль");
- string passwd = Console.ReadLine();
- Authenticate(passwd);
- Request();
- }
- }
- }
- public bool CheckAcces()
- {
- if (_realCustomer == null)
- {
- return false;
- }
- else return true;
- }
- }
- class Client
- {
- public void ClientCode(ICustomer customer)
- {
- customer.Request();
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Client client = new Client();
- ProxyCustomer proxyCustomer = new ProxyCustomer();
- client.ClientCode(proxyCustomer);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement