Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Net.Http.Headers;
- using System.Security.Cryptography.X509Certificates;
- namespace Автосервис4
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- CarService carService = new CarService();
- carService.Work();
- }
- }
- class CarService
- {
- private int _moneyBalance = 10000;
- private Dictionary<string, int> _priceList = new Dictionary<string, int>();
- private Queue<Car> _clients = new Queue<Car>();
- private Warehouse _warehouse = new Warehouse();
- public CarService()
- {
- AssignPriceList();
- }
- public void Work()
- {
- bool isRun = true;
- Console.WriteLine("Сколько клиентов принять за сегодня?");
- int quantityClients;
- do
- {
- Console.WriteLine("Введите положительное число");
- quantityClients = Utility.ReturnInputNumber();
- }
- while (quantityClients <= 0);
- Console.Clear();
- AddClient(quantityClients);
- while (isRun)
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.Write("Приехал автомобиль с поломкой: ");
- Console.WriteLine(_clients.Peek().Breakdown);
- Console.ForegroundColor = ConsoleColor.White;
- Console.ForegroundColor = ConsoleColor.Yellow;
- Console.WriteLine($"\nБаланс мастерской: {_moneyBalance}\n");
- Console.ForegroundColor = ConsoleColor.White;
- ShowPriceList();
- _warehouse.ShowParts();
- DiagnosticCar();
- _clients.Peek().ReplaceDetail(RepairCar());
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("Нажмите любую клавишу для приема следующего клиента");
- Console.ForegroundColor = ConsoleColor.White;
- _clients.Dequeue();
- if (_clients.Count == 0)
- {
- Console.ForegroundColor = ConsoleColor.DarkYellow;
- Console.WriteLine("\nКлиентов на сегодня больше нет");
- Console.ForegroundColor = ConsoleColor.White;
- isRun = false;
- }
- Console.ReadKey();
- Console.Clear();
- }
- }
- private void AddClient(int quantityClients)
- {
- for (int i = 0; i < quantityClients; i++)
- {
- _clients.Enqueue(new Car());
- }
- }
- private void DiagnosticCar()
- {
- int finalPrice = 0;
- CalculateFinalPrice(GetNecessaryPart(finalPrice));
- }
- private int GetNecessaryPart(int finalPrice)
- {
- string presentCar = _clients.Peek().Breakdown;
- if (_warehouse.GetListBreakdownAndParts().ContainsKey(presentCar))
- {
- Console.ForegroundColor = ConsoleColor.DarkYellow;
- Console.Write("\nТребуемая запчасть: ");
- Console.ForegroundColor = ConsoleColor.White;
- _warehouse.GetListBreakdownAndParts()[presentCar].ShowPrice();
- }
- return finalPrice += _warehouse.GetListBreakdownAndParts()[presentCar].Price;
- }
- private void CalculateFinalPrice(int finalPrice)
- {
- string presentClient = _clients.Peek().Breakdown;
- if (_priceList.ContainsKey(presentClient))
- {
- Console.ForegroundColor = ConsoleColor.DarkYellow;
- Console.Write("Цена за работу: ");
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine(_priceList[presentClient]);
- finalPrice += _priceList[presentClient];
- }
- Console.ForegroundColor = ConsoleColor.DarkYellow;
- Console.Write($"Итого: ");
- Console.ForegroundColor = ConsoleColor.White;
- Console.Write($"{finalPrice}");
- }
- private CarPart RepairCar()
- {
- var car = _clients.Peek();
- Console.WriteLine("");
- for (int i = 0; i < _warehouse.CarPartsCount; i++)
- {
- Console.WriteLine($"{i + 1} - {_warehouse.GetCarParts()[i].Title}");
- }
- Console.WriteLine($"\nВыбери запчасть:");
- int userInput = (Utility.ReturnInputNumber() - 1);
- if (userInput < 0 || userInput >= _warehouse.CarPartsCount)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("Неверная команда, клиент уехал");
- Console.ForegroundColor = ConsoleColor.White;
- }
- else
- {
- CarPart carPart = _warehouse.GetCarPart(userInput);
- ServeCar(carPart.Title, car);
- return carPart;
- }
- return null;
- }
- private void ServeCar(string selectedPart, Car car)
- {
- int installationPenalty = 600;
- double multiplier = 0.5;
- if (_warehouse.TryGetPart(selectedPart, out int partPrice, car, out int fineWrongPart, out int replacePrice, multiplier))
- {
- ApproveRequest(car, partPrice, replacePrice);
- }
- else if (fineWrongPart == installationPenalty)
- {
- AssignFine(fineWrongPart);
- }
- else
- {
- RejectRequest();
- }
- }
- private void ApproveRequest(Car car, int partPrice, int replacePrice)
- {
- Console.WriteLine("Запчасть в наличии, авто отремонтировали");
- Console.WriteLine($"Баланс мастерской {_moneyBalance} пополнился на {partPrice} (Стоимость запчасти)");
- _moneyBalance += partPrice;
- Console.WriteLine($"Баланс мастерской {_moneyBalance} пополнился на {replacePrice} (Стоимость ремонта)");
- _moneyBalance += replacePrice;
- Console.ForegroundColor = ConsoleColor.Yellow;
- Console.WriteLine($"\nБаланс мастерской {_moneyBalance}\n");
- Console.ForegroundColor = ConsoleColor.White;
- }
- private void AssignFine(int fineWrongPart)
- {
- _moneyBalance -= fineWrongPart;
- Console.ForegroundColor = ConsoleColor.Yellow;
- Console.WriteLine($"Штраф за установку не той запчасти {fineWrongPart} || Баланс мастерской {_moneyBalance}");
- Console.ForegroundColor = ConsoleColor.White;
- }
- private void RejectRequest()
- {
- int fine = 500;
- Console.WriteLine($"Запчасть отсутствует, клиент не доволен, вам штраф {fine}");
- _moneyBalance -= fine;
- Console.ForegroundColor = ConsoleColor.Yellow;
- Console.WriteLine($"\nБаланс мастерской {_moneyBalance}\n");
- Console.ForegroundColor = ConsoleColor.White;
- }
- private void ShowPriceList()
- {
- Console.ForegroundColor = ConsoleColor.DarkYellow;
- Console.WriteLine("Прайс лист: ");
- Console.ForegroundColor = ConsoleColor.White;
- foreach (var price in _priceList)
- {
- Console.WriteLine($"Поломка: {price.Key} || Цена ремонта: {price.Value}");
- }
- }
- private void AssignPriceList()
- {
- DetailCreator detailCreator = new DetailCreator();
- for (int i = 0; i < detailCreator.GetDetails().Count; i++)
- {
- _priceList.Add(detailCreator.GetBreakdown()[i], _warehouse.GetDetailPrices()[i]);
- }
- }
- }
- class Warehouse
- {
- private List<CarPart> _carParts = new List<CarPart>();
- private Dictionary<string, CarPart> _listBreakdownAndParts = new Dictionary<string, CarPart>();
- private DetailCreator _detailsCreator = new DetailCreator();
- private List<int> _detailPrices = new List<int>();
- public Warehouse()
- {
- FillStorage();
- FillBreakdownList();
- FillPricesList();
- }
- public int StarterReplacePrice { get; private set; } = 3000;
- public int SuspensionReplacePrice { get; private set; } = 1500;
- public int SparkPlugsReplacePrice { get; private set; } = 500;
- public int ThermostatReplacePrice { get; private set; } = 2000;
- public int CarPartsCount => _carParts.Count;
- public CarPart GetCarPart(int index)
- {
- return _carParts[index];
- }
- public bool TryGetPart(string selectedPart, out int partPrice, Car car, out int fineWrongPart, out int replacePrice, double multiplier)
- {
- foreach (var breakdown in _listBreakdownAndParts)
- {
- if (car.Breakdown == breakdown.Key && breakdown.Value.Title == selectedPart)
- {
- for (int i = 0; i < _carParts.Count; i++)
- {
- if (selectedPart == _carParts[i].Title)
- {
- partPrice = _carParts[i].Price;
- Console.WriteLine($"Со склада забрали {_carParts[i].Title} стоимостью {_carParts[i].Price}");
- replacePrice = (int)(_carParts[i].Price * multiplier);
- _carParts.Remove(_carParts[i]);
- fineWrongPart = 0;
- return true;
- }
- }
- partPrice = 0;
- replacePrice = 0;
- fineWrongPart = 0;
- return false;
- }
- }
- for (int i = 0; i < _carParts.Count; i++)
- {
- if (selectedPart == _carParts[i].Title)
- {
- _carParts.Remove(_carParts[i]);
- fineWrongPart = 600;
- replacePrice = 0;
- partPrice = 0;
- return false;
- }
- }
- partPrice = 0;
- replacePrice = 0;
- fineWrongPart = 0;
- return false;
- }
- public List<CarPart> GetCarParts()
- {
- return new List<CarPart>(_carParts);
- }
- public Dictionary<string, CarPart> GetListBreakdownAndParts()
- {
- return new Dictionary<string, CarPart>(_listBreakdownAndParts);
- }
- public void ShowParts()
- {
- Console.ForegroundColor = ConsoleColor.DarkYellow;
- Console.WriteLine("\nЗапчасти на складе:");
- Console.ForegroundColor = ConsoleColor.White;
- foreach (var part in _carParts)
- {
- Console.WriteLine($"Запчасть: {part.Title} || Цена: {part.Price}");
- }
- }
- public List<int> GetDetailPrices()
- {
- return new List<int>(_detailPrices);
- }
- private void FillPricesList()
- {
- _detailPrices.Add(StarterReplacePrice);
- _detailPrices.Add(SuspensionReplacePrice);
- _detailPrices.Add(SparkPlugsReplacePrice);
- _detailPrices.Add(ThermostatReplacePrice);
- }
- private void FillBreakdownList()
- {
- int breakdownQuantity = 4;
- for (int i = 0; i < breakdownQuantity; i++)
- {
- _listBreakdownAndParts.Add(_detailsCreator.GetBreakdown()[i], _carParts[i]);
- }
- }
- private void FillStorage()
- {
- _carParts.AddRange(_detailsCreator.GetDetails());
- int carPartsQuantity = 5;
- for (int i = 0; i < carPartsQuantity; i++)
- {
- AddRandomDetail();
- }
- }
- private void AddRandomDetail()
- {
- int number = Utility.GenerateRandomNumber(3);
- CarPart randomDetail = _detailsCreator.GetDetails()[number];
- _carParts.Add(randomDetail);
- }
- }
- class Car
- {
- private List<string> _breakdowns = new List<string>();
- private List<CarPart> _details = new List<CarPart>();
- private DetailCreator _detailCreator = new DetailCreator();
- private CarPart _carPart;
- public Car()
- {
- CreateBreakdown();
- FillCarParts();
- Breakdown = GetRandomBreakdown();
- BrokeDetail();
- }
- public string Breakdown { get; private set; }
- public string GetRandomBreakdown()
- {
- int number = Utility.GenerateRandomNumber(_breakdowns.Count);
- return new List<string>(_breakdowns)[number];
- }
- public void ReplaceDetail(CarPart newCarPart)
- {
- _details.Remove(GetBrokenDetail());
- _details.Add(newCarPart);
- }
- private CarPart GetBrokenDetail()
- {
- foreach (var detail in _details)
- {
- if (detail.IsBroken == true)
- {
- return detail;
- }
- }
- return null;
- }
- private void BrokeDetail()
- {
- for (int i = 0; i < _breakdowns.Count; i++)
- {
- if (Breakdown == _breakdowns[i])
- {
- _details[i].SwitchOnTrue();
- break;
- }
- }
- }
- private void FillCarParts()
- {
- _details.AddRange(_detailCreator.GetDetails());
- }
- private void CreateBreakdown()
- {
- _breakdowns.AddRange(_detailCreator.GetBreakdown());
- }
- }
- class DetailCreator
- {
- private List<CarPart> _details = new List<CarPart>();
- private List<string> _breakdowns = new List<string>();
- public DetailCreator()
- {
- FillCarParts();
- FillBreakdownList();
- }
- public List<CarPart> GetDetails()
- {
- return new List<CarPart>(_details);
- }
- public List<string> GetBreakdown()
- {
- return new List<string>(_breakdowns);
- }
- private void FillBreakdownList()
- {
- _breakdowns.Add("Скрежет, когда заводится");
- _breakdowns.Add("Стучит подвеска");
- _breakdowns.Add("Прыгают обороты двигателя");
- _breakdowns.Add("Перегревается двигатель");
- }
- private void FillCarParts()
- {
- _details.Add(new CarPart("Стартер", 4000, false));
- _details.Add(new CarPart("Рычаг подвески", 3000, false));
- _details.Add(new CarPart("Свечи", 1000, false));
- _details.Add(new CarPart("Термостат", 2000, false));
- }
- }
- class CarPart
- {
- public CarPart(string title, int price, bool isBroken)
- {
- Title = title;
- Price = price;
- IsBroken = isBroken;
- }
- public string Title { get; private set; }
- public int Price { get; private set; }
- public bool IsBroken { get; private set; }
- public void SwitchOnTrue()
- {
- IsBroken = true;
- }
- public void ShowPrice()
- {
- Console.WriteLine($"Цена - {Price}");
- }
- }
- class Utility
- {
- private static Random s_random = new Random();
- public static int GenerateRandomNumber(int number)
- {
- return s_random.Next(number);
- }
- public static int ReturnInputNumber()
- {
- int number;
- while (int.TryParse(Console.ReadLine(), out number) == false)
- {
- Console.WriteLine("Введено не число, попробуйте еще раз: ");
- }
- return number;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement