Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Autoservice
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<Detail> details = new List<Detail>
- {
- new Detail("A", 4),
- new Detail("B", 5),
- new Detail("C", 6),
- new Detail("D", 7),
- new Detail("E", 8),
- new Detail("F", 9),
- };
- Station station = new Station(details);
- station.Work(details);
- }
- }
- class Station
- {
- private List<Detail> _availableDetails;
- private static Random __random;
- private float _balance;
- static Station()
- {
- __random = new Random();
- }
- public Station(List<Detail> details)
- {
- _availableDetails = details;
- _balance = 0;
- }
- public void Work(List<Detail> details)
- {
- bool outOfDetails = false;
- while (outOfDetails == false)
- {
- VisualizeHeader();
- ReplaceDetail(InspectCar(details));
- outOfDetails = _availableDetails.All(detail => detail.Amount == 0);
- Console.Clear();
- }
- Console.WriteLine($"У вас закончились все детали. Зато вы заработали {_balance} денег!");
- Console.ReadKey();
- }
- private Detail InspectCar(List<Detail> details)
- {
- Detail detailToReplace = details[__random.Next(0, details.Count)];
- Console.WriteLine($"Вам надо заменить деталь {detailToReplace.Label} за {detailToReplace.Price * 1.5}.");
- return detailToReplace;
- }
- private void ReplaceDetail(Detail detailToReplace)
- {
- Console.Write("Какую деталь поставить? ");
- string requestedLabel = Console.ReadLine();
- Detail requstedDetail = _availableDetails.FirstOrDefault(detail => detail.Label == requestedLabel);
- if (requstedDetail != null)
- {
- float coefficient = 0.5f;
- float workPrice = (requstedDetail.Price + requstedDetail.Price * coefficient);
- if (requstedDetail.Amount > 0 && requstedDetail == detailToReplace)
- _balance += workPrice;
- else
- _balance -= workPrice;
- requstedDetail.Use();
- if (requstedDetail.Amount == 0)
- _availableDetails.Remove(requstedDetail);
- }
- else
- {
- Console.WriteLine("Детали с таким названием нет!");
- }
- Console.WriteLine(_balance);
- }
- public void VisualizeHeader()
- {
- Console.SetCursorPosition(0, 0);
- Console.WriteLine("----------Детали----------");
- Console.Write("Название ");
- foreach (var detail in _availableDetails)
- {
- Console.Write($"|{detail.Label}| ");
- }
- Console.WriteLine();
- Console.Write("Цена ");
- foreach (var detail in _availableDetails)
- {
- Console.Write($"|{detail.Price}| ");
- }
- Console.WriteLine();
- Console.Write("Количество ");
- foreach (var detail in _availableDetails)
- {
- Console.Write($"|{detail.Amount}| ");
- }
- Console.WriteLine();
- Console.WriteLine($"Баланс: {_balance}\n");
- }
- }
- class Detail
- {
- private static Random _random;
- public int Price { get; private set; }
- public string Label { get; private set; }
- public int Amount { get; private set; }
- static Detail()
- {
- _random = new Random();
- }
- public Detail(string label, int price)
- {
- Label = label;
- Price = price;
- int minAmount = 2; int maxAmount = 4;
- Amount = _random.Next(minAmount, maxAmount + 1);
- }
- public void Use()
- {
- Amount--;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment