Advertisement
Stray_Wolf

OOP_Autoservice

Aug 11th, 2022
879
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.79 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6.  
  7. namespace HW_45_OOP_AutoService
  8. {
  9.     internal class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Service service = new Service(new List<Client> {
  14.                 new Client("Андрей", 10000, new Auto("Audi", "Двигатель")),
  15.                 new Client("Макар", 10000, new Auto("Audi", "Двигатель")),
  16.                 new Client("Алексей", 10000, new Auto("Mercedes", "Двигатель")),
  17.                 new Client("Ибрагим", 10000, new Auto("Audi", "Двигатель")),
  18.                 new Client("Ланселот", 10000, new Auto("Audi", "Двигатель")),
  19.                 new Client("Антон", 10000, new Auto("Pegeout", "Тормоза")),
  20.                 new Client("Анатолий", 10000, new Auto("Lada", "Тормоза")),
  21.                 new Client("Валерий", 10000, new Auto("UAZ", "Генератор")),
  22.                 new Client("Григорий", 10000, new Auto("Niva", "Двигатель")),
  23.                 new Client("Алексей", 10000, new Auto("Chevrolet", "Подвеска")),
  24.                 new Client("Андрей", 10000, new Auto("Maybah", "Рулевая")),
  25.                 new Client("Соломон", 10000, new Auto("Citroen", "Стартер")),
  26.             });
  27.  
  28.             while (service.Clients.Count != 0)
  29.             {
  30.                 Console.WriteLine("Денег в кассе: " + service.MoneyCount + "\n\n");
  31.  
  32.                 service.ProceedClient();
  33.                 Console.ReadLine();
  34.                 Console.Clear();
  35.             }
  36.         }
  37.     }
  38.  
  39.     class Service
  40.     {
  41.         private int _moneyCount;
  42.         private int _partPrice;
  43.  
  44.         //тут задать бы автоприсвоение уникального id
  45.         private List<Client> _clients = new List<Client>();
  46.         private Warehouse _warehouse = new Warehouse(15, new List<Part> {
  47.             new Part("Двигатель", 10000, 1),
  48.             new Part("Двигатель", 10000, 2),
  49.             new Part("Двигатель", 10000, 3),
  50.             new Part("Двигатель", 10000, 4),
  51.             new Part("Генератор", 6000, 5),
  52.             new Part("Генератор", 6000, 6),
  53.             new Part("Генератор", 6000, 7),
  54.             new Part("Подвеска", 3500, 8),
  55.             new Part("Подвеска", 3500, 9),
  56.             new Part("Рулевая", 5200, 10),
  57.             new Part("Рулевая", 5200, 11),
  58.             new Part("Рулевая", 5200, 12),
  59.             new Part("Стартер", 4000, 13),
  60.             new Part("Тормоза", 5000, 14),
  61.             new Part("Тормоза", 5000, 15),
  62.         });
  63.  
  64.         public Service(List<Client> clients)
  65.         {
  66.             _clients = clients;
  67.         }
  68.  
  69.         public List<Client> Clients { get { return _clients; } set { _clients = value; } }
  70.         public int MoneyCount { get { return _moneyCount; } set { _moneyCount = value; } }
  71.         public int PartPrice { get { return _partPrice; } set { _partPrice = value; } }
  72.         public Warehouse Warehouse { get { return _warehouse; } set { _warehouse = value; } }
  73.  
  74.  
  75.         public void ProceedClient()
  76.         {
  77.             var currentClient = _clients.First();
  78.             Console.WriteLine($"Клиент - {currentClient.Name}, марка авто - {currentClient.Auto.Name}. Неисправность - {currentClient.Auto.MalfunctionDesc}");
  79.             TakePart(currentClient);
  80.             _clients.Remove(currentClient);
  81.         }
  82.  
  83.         public void TakePart(Client client)
  84.         {
  85.             string neededPart = client.Auto.MalfunctionDesc;
  86.             var searchResult = Warehouse.SearchPart(neededPart, ref _partPrice);
  87.  
  88.             if (searchResult)
  89.             {
  90.                 Repair();
  91.             }
  92.             else
  93.             {
  94.                 MoneyBack();
  95.             }
  96.         }
  97.  
  98.         public void Repair()
  99.         {
  100.             Console.WriteLine("Успешный ремонт !");
  101.             _moneyCount += _partPrice;
  102.            
  103.         }
  104.  
  105.         public void MoneyBack()
  106.         {
  107.             Console.WriteLine("Возврат денег + неустойка");
  108.             _moneyCount -= _partPrice;
  109.         }
  110.     }
  111.  
  112.     class Warehouse
  113.     {
  114.         private int _partsCount;
  115.         private List<Part> _partList = new List<Part>();
  116.  
  117.         public Warehouse(int partsCount, List<Part> partList)
  118.         {
  119.             PartsCount = partsCount;
  120.             _partList = partList;
  121.         }
  122.  
  123.         public int PartsCount { get { return _partsCount; } set { _partsCount = value; } }
  124.         public List<Part> PartsList { get { return _partList; } set { _partList = value; } }
  125.  
  126.         public bool SearchPart(string partName, ref int price)
  127.         {
  128.             Console.WriteLine("Ищем деталь . . .");
  129.             Thread.Sleep(1000);
  130.             foreach (var part in _partList)
  131.             {
  132.                 if (part.Name == partName)
  133.                 {
  134.                     price = part.Price;
  135.                     Console.WriteLine(part.Name + " " + part.Id);
  136.                     Console.WriteLine("цена детали " + price);
  137.                     Console.WriteLine("Есть деталь !, передаем на ремонт !");
  138.  
  139.                     RemovePart(part.Id);
  140.  
  141.                     return true;
  142.                 }
  143.             }
  144.             Console.WriteLine("Такой детали нет");
  145.             return false;
  146.         }
  147.  
  148.         public void RemovePart(int id)
  149.         {
  150.             _partList.RemoveAll(x => x.Id == id);
  151.         }
  152.     }
  153.  
  154.     class Part
  155.     {
  156.         private string _name;
  157.         private int _price;
  158.         private int _id;
  159.  
  160.         public Part(string name, int price, int id)
  161.         {
  162.             Name = name;
  163.             _price = price;
  164.             _id = id;
  165.         }
  166.  
  167.         public string Name { get { return _name; } set { _name = value; } }
  168.         public int Price { get { return _price; } set { _price = value; } }
  169.         public int Id { get { return _id; } }
  170.     }
  171.  
  172.     class Client
  173.     {
  174.         public Auto Auto;
  175.  
  176.         public string Name;
  177.         private int _money;
  178.  
  179.         public Client(string name, int money, Auto auto)
  180.         {
  181.             Name = name;
  182.             _money = money;
  183.             Auto = auto;
  184.         }
  185.  
  186.         public int Money { get { return _money; } }
  187.     }
  188.  
  189.     class Auto
  190.     {
  191.         public string Name;
  192.         public string MalfunctionDesc;
  193.  
  194.         public Auto(string name, string malfunctionDesc)
  195.         {
  196.             Name = name;
  197.             MalfunctionDesc = malfunctionDesc;
  198.         }
  199.     }
  200. }
  201.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement