Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Reflection.Metadata.Ecma335;
- using System.Runtime.ConstrainedExecution;
- using System.Text;
- using System.Threading.Tasks;
- namespace Task13
- {
- class Program
- {
- static void Main(string[] args)
- {
- AutoService autoService = new AutoService();
- autoService.Work();
- }
- }
- class AutoService
- {
- private float _money = 1000;
- private float _jobMultiplier = 1.2f;
- private List<Cell> _cellsParts = new List<Cell>();
- private Queue<Car> _cars = new Queue<Car>();
- private List<string> _cashiersCheck = new List<string>();
- public AutoService()
- {
- List<Part> parts = new List<Part>();
- CreateParts(parts);
- FillCells(parts);
- AddCarsToQueue(parts);
- }
- public void Work()
- {
- bool isWork = true;
- bool isMendCar;
- int inspectionServiceableCar = 500;
- int workPrice;
- while (isWork)
- {
- Console.Clear();
- isMendCar = true;
- workPrice = 0;
- int percent = 100;
- string userInput;
- float jobPercent = _jobMultiplier * percent - percent;
- _cashiersCheck.Clear();
- ShowInfo();
- Console.WriteLine($"\nМашин в очереди: {_cars.Count}\nЦена за работу = {Math.Round(jobPercent)}% от суммы стоимости заменяемых деталей");
- Console.Write("Нажмите любую клавишу, чтобы обслужить следующую машину...");
- Console.ReadKey();
- if (GetServiceabilityCar())
- {
- Console.Clear();
- Console.WriteLine($"По результатам технического осмотра автомобиля, выяснено, что автомобиль исправен!\nЗа технический осмотр автомобиля ={inspectionServiceableCar}$");
- Console.ReadKey();
- _money += inspectionServiceableCar;
- }
- else
- {
- while (isMendCar)
- {
- ShowInfo();
- _cars.Peek().ShowInfo();
- Console.Write("\nВведите название детали, которую необходимо заменить: ");
- userInput = Console.ReadLine();
- workPrice += GetMoneyForReplacingPart(TryReplacePart(userInput), userInput);
- Console.WriteLine(_cashiersCheck.Last());
- if (GetServiceabilityCar())
- isMendCar = false;
- else
- isMendCar = TryMendCar();
- }
- ShowCashiersCheck(workPrice, GetServiceabilityCar());
- _money += workPrice;
- }
- _cars.Dequeue();
- isWork = _cars.Count > 0;
- if (isWork == false)
- {
- Console.WriteLine($"Все машины обслужены, конец рабочего дня!\nВыручка за сегодня {_money}$");
- Console.ReadKey();
- }
- if (_money < 0)
- {
- isWork = false;
- Console.Write("Вы обанкротились! Конец бизнесу!");
- Console.ReadKey();
- }
- }
- }
- private bool GetServiceabilityCar()
- {
- return _cars.Peek().IsServiceable();
- }
- private void ShowInfo()
- {
- Console.Clear();
- Console.WriteLine($"Автосервис\nБаланс: {_money}$\n\nСклад:");
- foreach (var cell in _cellsParts)
- {
- cell.ShowInfo();
- }
- }
- private bool TryReplacePart(string userInput)
- {
- if (FindDetail(userInput) && _cars.Peek().TryGetNotServiceablePart(userInput))
- {
- TakePart(userInput);
- _cars.Peek().ReplacePart(userInput);
- return true;
- }
- else
- {
- return false;
- }
- }
- private int GetMoneyForReplacingPart(bool IsReplacingPart, string userInput)
- {
- int workPrice = 0;
- int penalty = 500;
- int jobMultiplier;
- if (IsReplacingPart)
- {
- workPrice = _cars.Peek().GetPricePart(userInput);
- jobMultiplier = (int)Math.Round(workPrice * _jobMultiplier - workPrice);
- _cashiersCheck.Add($"Заменена {userInput}. Цена замены детали ={workPrice}$ + Цена за работу ={jobMultiplier}$");
- workPrice += jobMultiplier;
- }
- else
- {
- workPrice -= penalty;
- _cashiersCheck.Add($"Детали ({userInput}) нет, или такая деталь в машине исправна! Штраф ={penalty}$");
- }
- return workPrice;
- }
- private void ShowCashiersCheck(int workPrice, bool isServiceableCar)
- {
- int penalty = 1000;
- Console.Clear();
- if (isServiceableCar)
- {
- Console.WriteLine($"~Чек-лист~\nАвтомобиль успешно починен!\n");
- ShowCashiersCheck(workPrice);
- }
- else
- {
- Console.WriteLine($"~Чек-лист~\nАвтомобиль не был починен! Штраф ={penalty}$\n");
- ShowCashiersCheck(workPrice - penalty);
- _money -= penalty;
- }
- Console.ReadKey();
- }
- private void ShowCashiersCheck(int workPlace)
- {
- foreach (var checkString in _cashiersCheck)
- {
- Console.WriteLine(checkString);
- }
- Console.WriteLine($"\nИТОГО {workPlace}$");
- }
- private bool TryMendCar()
- {
- const string CommandExit = "н";
- const string CommandContinue = "д";
- const string StringContinueOrExit = $"Продолжить чинить автомобиль ({CommandContinue}/{CommandExit}): ";
- bool isMandCar = true;
- while (isMandCar)
- {
- Console.Write(StringContinueOrExit);
- string userInput = Console.ReadLine();
- switch (userInput)
- {
- case CommandContinue:
- return true;
- case CommandExit:
- isMandCar = false;
- break;
- default:
- Console.Write("такой команды нет!");
- Console.ReadKey();
- break;
- }
- }
- return false;
- }
- private bool FindDetail(string userInput)
- {
- foreach (var cell in _cellsParts)
- {
- if (cell.TryFindDetail(userInput))
- if (cell.HavePart)
- return true;
- }
- return false;
- }
- private void TakePart(string userInput)
- {
- foreach (var cell in _cellsParts)
- {
- if (cell.TryFindDetail(userInput))
- cell.TakePart();
- }
- }
- private void FillCells(List<Part> parts)
- {
- int minCountParts = 3;
- int maxCountParts = 6;
- Random random = new Random();
- foreach (var part in parts)
- {
- _cellsParts.Add(new Cell(part, random.Next(minCountParts, maxCountParts)));
- }
- }
- private void CreateParts(List<Part> parts)
- {
- int minPricePart = 250;
- int maxPricePart = 750;
- Random random = new Random();
- parts.AddRange(new Part[] {
- new Part("деталь_1", random.Next(minPricePart, maxPricePart), true),
- new Part("деталь_2", random.Next(minPricePart, maxPricePart), true),
- new Part("деталь_3", random.Next(minPricePart, maxPricePart), true),
- new Part("деталь_4", random.Next(minPricePart, maxPricePart), true),
- new Part("деталь_5", random.Next(minPricePart, maxPricePart), true)
- });
- }
- private void AddCarsToQueue(List<Part> parts)
- {
- int minCountCars = 2;
- int maxCountCars = 6;
- Random random = new Random();
- int countCars = random.Next(minCountCars, maxCountCars);
- for (int i = 0; i < countCars; i++)
- {
- _cars.Enqueue(new Car(parts));
- }
- }
- }
- class Car
- {
- private List<Part> _parts = new List<Part>();
- public Car(List<Part> parts)
- {
- foreach (var part in parts)
- {
- _parts.Add(new Part(part.Name, part.Price, SetRandomBoolValue()));
- }
- }
- public void ShowInfo()
- {
- Console.WriteLine("\n\n*Идёт обслуживание машины*\nСписок неисправных деталей:");
- var defectiveParts = _parts.Where(part => part.IsServiceable == false);
- foreach (var part in defectiveParts)
- {
- Console.WriteLine($"{part.Name}");
- }
- }
- public bool IsServiceable()
- {
- var result = _parts.Where(part => part.IsServiceable == false);
- return result.Count() == 0;
- }
- public void ReplacePart(string userInput)
- {
- foreach (var part in _parts)
- {
- if (part.Name == userInput)
- part.Replace();
- }
- }
- public bool TryGetNotServiceablePart(string userInput)
- {
- foreach (var part in _parts)
- {
- if (part.Name == userInput && part.IsServiceable == false)
- return true;
- }
- return false;
- }
- public int GetPricePart(string userInput)
- {
- foreach (var part in _parts)
- {
- if (part.Name == userInput)
- return part.Price;
- }
- return 0;
- }
- private bool SetRandomBoolValue()
- {
- int numberOfOutcomes = 2;
- Random random = new Random();
- return random.Next(0, numberOfOutcomes) == 1;
- }
- }
- class Cell
- {
- public Part Part { get; private set; }
- public int Count { get; private set; }
- public bool HavePart => Count > 0;
- public Cell(Part part, int count)
- {
- Part = part;
- Count = count;
- }
- public void ShowInfo()
- {
- Console.WriteLine($"{Part.Name}: {Count} шт. ={Part.Price}$");
- }
- public bool TryFindDetail(string userInput)
- {
- return Part.Name == userInput;
- }
- public void TakePart()
- {
- Count--;
- }
- }
- class Part
- {
- public string Name { get; private set; }
- public int Price { get; private set; }
- public bool IsServiceable { get; private set; }
- public Part(string name, int price, bool isServiceable)
- {
- Name = name;
- Price = price;
- IsServiceable = isServiceable;
- }
- public void Replace()
- {
- IsServiceable = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement