taxi service
unknown
csharp
2 years ago
3.1 kB
13
Indexable
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("Merceses", "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($"Вы поедете с {addressFrom} в {addressWhere}. Расстояние: {Math.Round(distance, 2)}км.");
// формула стоимости такси: (расстояние : корректировка) * коэффициент нагруженности * минимальная цена
// 1 - нет нагруженности
// 1.5 - низкая нагруженность
// 2 - средняя нагрузка
// 2.5 - высокая нагрузка
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) + "kzt.");
//Console.WriteLine("Стоимость одного километра: " + Math.Round(cost / distance) + "kzt."); ///////////////////////
Driver CurrentDriver = drivers[random.Next(0, drivers.Length)];
Console.WriteLine("Ваш водитель:" + CurrentDriver.Name + ", на " + CurrentDriver.Car.Brand + CurrentDriver.Car.Model +
CurrentDriver.Car.NumberPlate + " цвета" + CurrentDriver.Car.Color);
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