Advertisement
OwlyOwl

auto-service

Jul 20th, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.26 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace AutoService
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             Service service = new Service();
  11.             service.GetDetails();
  12.             service.CreateQueue();
  13.             service.Work();
  14.         }
  15.     }
  16.  
  17.     class Service
  18.     {
  19.         public int Balance { get; private set; }
  20.         public int WorkCost { get; private set; }
  21.  
  22.         public int Penalty { get; private set; }
  23.         private List<Detail> details = new List<Detail>();
  24.         private Queue<Client> queueLine = new Queue<Client>();
  25.  
  26.         public Service()
  27.         {
  28.             Balance = 0;
  29.             WorkCost = 200;
  30.             Penalty = 300;
  31.             List<Detail> details = new List<Detail>();
  32.             Queue<Client> queueLine = new Queue<Client>();
  33.         }
  34.  
  35.         public void CreateQueue()
  36.         {
  37.             for (int i = 0; i < 12; i++)
  38.             {
  39.                 Client newClient = new Client();
  40.                 queueLine.Enqueue(newClient);
  41.             }
  42.         }
  43.  
  44.         public void GetDetails()
  45.         {
  46.             for (int i = 0; i < 15; i++)
  47.             {
  48.                 Detail newDetail = new Detail();
  49.                 details.Add(newDetail);
  50.             }
  51.         }
  52.  
  53.         public void ShowAllDetails()
  54.         {
  55.             int i = 1;
  56.             foreach (var item in details)
  57.             {
  58.                 Console.WriteLine($"[{i}] - деталь размера:  {item.Size}");
  59.                 i++;
  60.             }
  61.         }
  62.  
  63.         public void ReplaceDetail(int number, Client client)
  64.         {
  65.             if (details[number - 1].Size == client.ShowProblem())
  66.             {
  67.                 Balance += details[number - 1].Price + WorkCost;
  68.                 details.RemoveAt(number - 1);
  69.                 Console.WriteLine("Деталь успешно заменена!");
  70.             }
  71.             else
  72.             {
  73.                 Balance -= Penalty;
  74.                 Console.WriteLine("Выбрана неподходящая деталь, выплачен штраф.");
  75.             }
  76.         }
  77.         public void Work()
  78.         {
  79.             while (queueLine.Count > 0)
  80.             {
  81.                 Console.WriteLine("Auto-Service Balance - " + Balance);
  82.                 var currentClient = queueLine.Dequeue();
  83.                 currentClient.ShowProblem();
  84.                 ShowAllDetails();
  85.                 Console.WriteLine("Заменить деталь?\n1 - Yes\n2 - No");
  86.                 int userChoice = Convert.ToInt32(Console.ReadLine());
  87.                 if (userChoice == 1)
  88.                 {
  89.                     Console.WriteLine("\nВведите номер детали со склада?");
  90.                     userChoice = Convert.ToInt32(Console.ReadLine());
  91.                     ReplaceDetail(userChoice, currentClient);
  92.  
  93.                 }
  94.                 else
  95.                 {
  96.                     Balance -= Penalty;
  97.                     Console.WriteLine("Клиенту отказано в ремонте, выплачен штраф. Нажмите ввод, чтобы продолжить.");
  98.                     Console.ReadKey();
  99.                 }
  100.                 Console.Clear();
  101.             }
  102.             Console.WriteLine("Рабочий день окончен! Денег в кассе - " + Balance);
  103.         }
  104.  
  105.  
  106.     }
  107.  
  108.     class Detail
  109.     {
  110.         public int Size { get; private set; }
  111.         public int Price { get; private set; }
  112.  
  113.         public Detail()
  114.         {
  115.             Random rand = new Random();
  116.             Size = rand.Next(1, 10);
  117.             Price = rand.Next(100, 300);
  118.         }
  119.     }
  120.  
  121.     class Client
  122.     {
  123.         public int Money { get; private set; }
  124.         public Detail BrokenDetail { get; private set; }
  125.  
  126.         public Client()
  127.         {
  128.             Money = 1000;
  129.             Detail brokenDetail = new Detail();
  130.             BrokenDetail = brokenDetail;
  131.         }
  132.  
  133.         public void Pay(int sum)
  134.         {
  135.             Money -= sum;
  136.         }
  137.  
  138.         public int ShowProblem()
  139.         {
  140.             Console.WriteLine("Сломана деталь размера - " + BrokenDetail.Size);
  141.             return BrokenDetail.Size;
  142.         }
  143.     }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement