Taxi

mail@pastecode.io avatar
unknown
csharp
2 months ago
2.6 kB
9
Indexable
Never
Driver[] drivers = new Driver[]
{
    new Driver("Mark", "Toyota", "Camry", "blue", "123"),
    new Driver("John", "BMW", "xDrive", "red", "691"),
    new Driver("Adam", "Ford", "Mustang", "white", "777"),

};

Console.Write("Откуда: ");
string from = Console.ReadLine();
Console.Write("Куда: ");
string to = Console.ReadLine();
Console.WriteLine("Ваш заказ принят!");
Console.WriteLine($"Вы поедите с {from} до {to}");


Random rand = new Random();

//Расстояние
float distanceKm = Convert.ToSingle(rand.Next(6));
float distanceM = Convert.ToSingle(rand.Next(100));
Console.WriteLine($"Расстояние: {Math.Round(distanceKm, 2)},{Math.Round(distanceM, 2)} км");

//Нагруженность
float[] traffic = new float[4] { 1f, 1.5f, 2f, 2.5f };
int randNumTraffic = rand.Next(traffic.Length);
float randTraffic = traffic[randNumTraffic];
string defTraffic = "нет";

switch (randTraffic)
{
    case 1f:
        defTraffic = "нет";
        break;
    case 1.5f:
        defTraffic = "маленькая";
        break;
    case 2f:
        defTraffic = "средняя";
        break;
    case 2.5f:
        defTraffic = "большая";
        break;
}

Console.WriteLine($"Сейчас {defTraffic} нагруженность");

//Корректировка
float correction = 1.75f;

//Мин стоимость поездки
float minTravCost = 400f;

//Стоимость поездки
float travCost = ((distanceKm + (distanceM/100))/ correction) * randTraffic * minTravCost;

if (travCost < 400f)
{
    travCost = 400f;
}

Console.WriteLine($"Стоимость поездки: {Math.Round(travCost)} тг");

//Время
int time = rand.Next(11);

//Ваш водитель прибудет через
int randNumDriver = rand.Next(drivers.Length);
Console.WriteLine($"Ваш водитель: {drivers[randNumDriver].Name}, {drivers[randNumDriver].CarCompany}, " +
                  $"{drivers[randNumDriver].CarModel}, {drivers[randNumDriver].Colour}, " +
                  $"{drivers[randNumDriver].GovNumber} прибудет через {time} минуты");


class Driver
{
    public string Name;
    public string CarCompany;
    public string CarModel;
    public string Colour;
    public string GovNumber;

    public Driver(string name, string carCompany, string carModel, string colour, string govNumber)
    {
        Name = name;
        CarCompany = carCompany;
        CarModel = carModel;
        Colour = colour;
        GovNumber = govNumber;
    }
}
Leave a Comment