Taxi

 avatar
user_1747955
csharp
a year ago
2.8 kB
3
Indexable
using System;

Console.OutputEncoding = System.Text.Encoding.UTF8;

Driver[] drivers = new Driver[]{
    new Driver("John", new Car("Toyota", "Camry", "Black", "010AAA06")),
    new Driver("Tom", new Car("Honda", "Civic", "Red", "020HHH06")),
    new Driver("Olzhas", new Car("Mercedes", "S500", "White", "007OLJ06"))
};

Random random = new Random();
float distance = random.NextSingle() * (5.0f + 0.0f) - 0.0f;

Console.Write("Откуда хотите поехать?: ");
string addressFrom = Console.ReadLine();
Console.Write("Куда хотите поехать?: ");
string addressWhere = Console.ReadLine();
Console.WriteLine("Ваш заказ принят!");
Console.WriteLine($"Вы поедете с {addressFrom} до {addressWhere}, расстояние - {Math.Round(distance, 2)} км.");

const float korrektirovka = 1.75f;
const float noLoad = 1;
const float lowLoad = 1.5f;
const float mediumLoad = 2;
const float highLoad = 2.5f;
const int minPrice = 400;
float currentLoad;

switch (random.Next(0, 4))
{
    case 0:
        currentLoad = noLoad;
        Console.WriteLine("Сейчас нет нагруженности.");
        break;
    case 1:
        currentLoad = lowLoad;
        Console.WriteLine("Сейчас низкая нагруженность.");
        break;
    case 2:
        currentLoad = mediumLoad;
        Console.WriteLine("Сейчас средняя нагруженность.");
        break;
    case 3:
        currentLoad = highLoad;
        Console.WriteLine("Сейчас высокая нагруженность.");
        break;
    default:
        currentLoad = 0;
        break;
}

float cost = (distance / korrektirovka) * currentLoad * minPrice;
Console.WriteLine($"Стоимость поездки: {Math.Round(cost)} тг.");

Driver currentDriver = drivers[random.Next(0, drivers.Length)];
int arrivalTime = random.Next(1, 11);

Console.WriteLine($"Ваш водитель: {currentDriver.Name}, {currentDriver.Car.Brand} {currentDriver.Car.Model}, цвет: {currentDriver.Car.Color}, гос. номер: {currentDriver.Car.NumberPlate} прибудет примерно через {arrivalTime} мин.");

class Driver
{
    public string Name;
    public Car Car;

    public Driver(string name, Car car)
    {
        Name = name;
        Car = car;
    }
}

class Car
{
    public string Brand;   // марка 
    public string Model;   // модель
    public string Color;   // цвет авто
    public string NumberPlate; // номер авто

    public Car(string brand, string model, string color, string numberPlate)
    {
        Brand = brand;
        Model = model;
        Color = color;
        NumberPlate = numberPlate;
    }
}
Editor is loading...
Leave a Comment