Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp1
- {
- class Program
- {
- static void Main(string[] args)
- {
- CarService carService = new CarService();
- Car car = new Car();
- bool isOpen = true;
- Console.WriteLine("Добро пожаловать в автосервис");
- while (isOpen)
- {
- Console.WriteLine("Выберите команду");
- Console.WriteLine("1 - Автосервис\n" + "0 - Выход из программы\n");
- int userInput = Convert.ToInt32(Console.ReadLine());
- Console.Clear();
- switch (userInput)
- {
- case 1:
- Detail brokenDetail = car.GetBrokenDetail();
- float priceForRepair = carService.GetRepairPrice(brokenDetail);
- Console.WriteLine("Цена починки автомобиля " + priceForRepair + "\n");
- carService.CheckMoneyBalance();
- Console.WriteLine("Выберите какую деталь машины заменить");
- car.ShowDetailsInfo();
- int userIndex = Convert.ToInt32(Console.ReadLine()) - 1;
- bool isRepaired = carService.IsDetailRepaired(car.GetDetail(userIndex));
- if (isRepaired == true)
- {
- if (brokenDetail == car.GetDetail(userIndex))
- {
- carService.Checklist();
- }
- else
- {
- Console.WriteLine("\nВы заменили не ту деталь\nАвтосервис должен возместить ущерб клиенту");
- carService.PayForDamage();
- }
- }
- break;
- case 0:
- isOpen = false;
- break;
- default:
- Console.WriteLine("Недопустимое значение");
- break;
- }
- }
- }
- }
- class Car
- {
- private Random _random = new Random();
- private Detail[] _details = new Detail[]
- {
- new Motor(), new Suspension(), new Battery(), new Wheel(), new Shaft()
- };
- public void ShowDetailsInfo()
- {
- for (int i = 0; i < _details.Length; i++)
- {
- Console.WriteLine(i + 1 + ") " + _details[i].Name);
- }
- }
- public Detail GetDetail(int index)
- {
- return _details[index];
- }
- public Detail GetBrokenDetail()
- {
- int index = _random.Next(0, _details.Length);
- Console.WriteLine("У автомобиля сломался(сь): " + _details[index].Name);
- return _details[index];
- }
- }
- class CarService
- {
- private Warehouse _warehouse = new Warehouse();
- private float _money = 5000f;
- private int _fine = 1000;
- private float _priceForRepair;
- public float GetRepairPrice(Detail brokenDetail)
- {
- _priceForRepair = brokenDetail.Price + brokenDetail.Price / 2f;
- return _priceForRepair;
- }
- public bool IsDetailRepaired(Detail brokenDetail)
- {
- bool isFind = false;
- for (int i = 0; i < _warehouse.GetDetails().Length; i++)
- {
- if (_warehouse.GetDetails()[i].Name == brokenDetail.Name)
- {
- _warehouse.DeleteDetail(i);
- Console.WriteLine("\nДеталь заменена");
- isFind = true;
- break;
- }
- }
- if (isFind == false)
- {
- Console.WriteLine("\nДетали нет на складе\nАвтосервис должен выплатить штраф");
- PayFine();
- }
- return isFind;
- }
- public void PayForDamage()
- {
- Console.WriteLine("Оплата ущерба " + _priceForRepair);
- _money -= _priceForRepair;
- CheckMoneyBalance();
- }
- private void PayFine()
- {
- Console.WriteLine("Оплата штрафа " + _fine);
- _money -= _fine;
- CheckMoneyBalance();
- }
- public void Checklist()
- {
- Console.WriteLine("Выплата за ремонт " + _priceForRepair);
- _money += _priceForRepair;
- CheckMoneyBalance();
- }
- public void CheckMoneyBalance()
- {
- if(_money <= 0)
- {
- _money = 0;
- }
- Console.WriteLine("Баланс денег автосервиса " + _money + "\n");
- }
- }
- class Warehouse
- {
- private Car car = new Car();
- private Detail[] _details = new Detail[]
- {
- new Motor(), new Motor(), new Motor(),
- new Suspension(),
- new Battery(), new Battery(), new Battery(),
- new Wheel(), new Wheel(), new Wheel(), new Wheel(),
- new Shaft(), new Shaft()
- };
- public Detail[] GetDetails()
- {
- return (Detail[])_details.Clone();
- }
- public void DeleteDetail(int index)
- {
- Detail[] tempArray = new Detail[_details.Length - 1];
- for (int i = 0; i < index; i++)
- {
- tempArray[i] = _details[i];
- }
- for (int i = index; i < tempArray.Length; i++)
- {
- tempArray[i] = _details[i + 1];
- }
- _details = tempArray;
- }
- }
- abstract class Detail
- {
- public string Name { get; protected set; }
- public int Price { get; protected set; }
- }
- class Motor : Detail
- {
- public Motor() : base()
- {
- Name = "Мотор";
- Price = 1500;
- }
- }
- class Suspension : Detail
- {
- public Suspension() : base()
- {
- Name = "Подвеска";
- Price = 2000;
- }
- }
- class Battery : Detail
- {
- public Battery() : base()
- {
- Name = "Аккумулятор";
- Price = 200;
- }
- }
- class Wheel : Detail
- {
- public Wheel() : base()
- {
- Name = "Колесо";
- Price = 100;
- }
- }
- class Shaft : Detail
- {
- public Shaft() : base()
- {
- Name = "Вал";
- Price = 250;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement