コード例 #1
0
        private static void ExecuteDriveCommand(string[] command, Car car, Truck truck, Bus bus)
        {
            double distance = double.Parse(command[2]);

            if (command[1] == "Car")
            {
                if (car.CanTravel(distance))
                {
                    car.Drive(distance);
                    Console.WriteLine($"Car travelled {car.DistanceTravelled} km");
                }
                else
                {
                    Console.WriteLine("Car needs refueling");
                }
            }
            else if (command[1] == "Truck")
            {
                if (truck.CanTravel(distance))
                {
                    truck.Drive(distance);
                    Console.WriteLine($"Truck travelled {truck.DistanceTravelled} km");
                }
                else
                {
                    Console.WriteLine("Truck needs refueling");
                }
            }
            else if (command[1] == "Bus")
            {
                if (bus.CanTravel(distance))
                {
                    bus.DriveWithPassangers(distance);
                    Console.WriteLine($"Bus travelled {bus.DistanceTravelled} km");
                }
                else
                {
                    Console.WriteLine("Bus needs refueling");
                }
            }
        }