Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.29 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Zamestitel
  5. {
  6.  
  7.     public interface ICustomer
  8.     {
  9.         void Request();
  10.     }
  11.     class RealCustomer : ICustomer
  12.     {
  13.         private string firstname = "Denis";
  14.         private string lastname = "Smirnov";
  15.         private int age = 20;
  16.         public string[] ShopList = new string[5] { "car", "bread", "milk", "moto", "lemon" };
  17.         Queue<string> ShopBasket = new Queue<string>();
  18.  
  19.         private void AddToShopBasket()
  20.         {
  21.             string product = Console.ReadLine();
  22.             while (product != "stop")
  23.             {
  24.                 ShopBasket.Enqueue(product);
  25.                 product = Console.ReadLine();
  26.             }
  27.         }
  28.         private void ShowShopBasket()
  29.         {
  30.             foreach( string list in ShopBasket)
  31.             {
  32.                 Console.WriteLine(list);
  33.             }
  34.         }
  35.         public void Request()
  36.         {
  37.             Console.WriteLine("1.Добавить в корзину товары");
  38.             Console.WriteLine("2.Посмотреть корзину");
  39.             Console.WriteLine("3.Личный кабинет");
  40.             Console.WriteLine("4.Выйти");
  41.             int number = Convert.ToInt32(Console.ReadLine());
  42.             if (number == 1)
  43.             {
  44.                 Console.WriteLine("Введите название товаров, которые вы хотите добавить в корзину(Для отмены введите stop)");
  45.                 AddToShopBasket();
  46.                 this.Request();
  47.             }
  48.             else if (number == 2)
  49.             {
  50.                 Console.WriteLine("В корзине: ");
  51.                 ShowShopBasket();
  52.                 this.Request();
  53.             }
  54.             else if(number == 3)
  55.             {
  56.                 Console.WriteLine(firstname);
  57.                 Console.WriteLine(lastname);
  58.                 Console.WriteLine(age);
  59.                 this.Request();
  60.             }
  61.             else if(number == 4)
  62.             {
  63.                 Environment.Exit(0);
  64.             }
  65.         }
  66.      
  67.     }
  68.     class ProxyCustomer : ICustomer
  69.     {
  70.        
  71.         private RealCustomer _realCustomer;
  72.         public string password = "test";
  73.         public string[] ShopList = new string[5] { "car", "bread", "milk", "moto", "lemon" };
  74.  
  75.         private void ShowShopList()
  76.         {
  77.             for(int i = 0; i < 5; i++)
  78.             {
  79.                 Console.WriteLine(ShopList[i]);
  80.             }
  81.         }
  82.         private void Authenticate(string passwd)
  83.         {
  84.             if (password == passwd)
  85.             {
  86.                 Console.WriteLine("Вы успешно зашли");
  87.                 this._realCustomer = new RealCustomer();
  88.             }
  89.             else Console.WriteLine("Повторите попытку");
  90.         }
  91.         public void Request()
  92.         {
  93.             if(this.CheckAcces())
  94.             {
  95.                 this._realCustomer.Request();
  96.             }
  97.             else
  98.             {
  99.                 Console.WriteLine("1.Посмотреть список товаров");
  100.                 Console.WriteLine("2.Авторизоваться");
  101.                 int number = Convert.ToInt32(Console.ReadLine());
  102.                 if(number == 1)
  103.                 {
  104.                     ShowShopList();
  105.                     Request();
  106.                 }
  107.                 if(number == 2)
  108.                 {
  109.                     Console.WriteLine("Введите пароль");
  110.                     string passwd = Console.ReadLine();
  111.                     Authenticate(passwd);
  112.                     Request();
  113.                 }
  114.             }
  115.         }
  116.         public bool CheckAcces()
  117.         {
  118.             if (_realCustomer == null)
  119.             {
  120.                 return false;
  121.             }
  122.             else return true;
  123.         }
  124.     }  
  125.     class Client
  126.     {
  127.         public void ClientCode(ICustomer customer)
  128.         {
  129.             customer.Request();
  130.         }
  131.     }
  132.  
  133.  
  134.     class Program
  135.     {
  136.         static void Main(string[] args)
  137.         {
  138.             Client client = new Client();
  139.             ProxyCustomer proxyCustomer = new ProxyCustomer();
  140.             client.ClientCode(proxyCustomer);
  141.          
  142.         }
  143.     }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement