private static void DriveAndRefuel(Vehicles car, Vehicles truck, Vehicles bus)
    {
        int count = int.Parse(Console.ReadLine());

        for (int i = 0; i < count; i++)
        {
            string[] args = Console.ReadLine()
                            .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            string activity = args[0];
            string type     = args[1];
            try
            {
                switch (activity)
                {
                case "Drive":
                    double km = double.Parse(args[2]);
                    if (type == "Car")
                    {
                        car.DrivenAGivenDistance(km);
                    }
                    else if (type == "Truck")
                    {
                        truck.DrivenAGivenDistance(km);
                    }
                    else
                    {
                        bus.DrivenAGivenDistance(km);
                    }
                    break;

                case "Refuel":
                    double liters = double.Parse(args[2]);
                    if (type == "Car")
                    {
                        car.RefueledVehicles(liters);
                    }
                    else if (type == "Truck")
                    {
                        truck.RefueledVehicles(liters);
                    }
                    else
                    {
                        bus.RefueledVehicles(liters);
                    }
                    break;

                case "DriveEmpty":
                    km = double.Parse(args[2]);
                    bus.DrivenAGivenDistance(km, false);
                    break;
                }
            }
            catch (ArgumentException argEx)
            {
                Console.WriteLine(argEx.Message);
            }
        }
    }
Exemplo n.º 2
0
    private static void DriveAndRefuel(Vehicles car, Vehicles truck)
    {
        int count = int.Parse(Console.ReadLine());

        for (int i = 0; i < count; i++)
        {
            string[] args = Console.ReadLine()
                            .Split(" ", StringSplitOptions.RemoveEmptyEntries);

            string activity = args[0];
            string type     = args[1];

            switch (activity)
            {
            case "Drive":
                double km = double.Parse(args[2]);
                if (type == "Car")
                {
                    Console.WriteLine(car.DrivenAGivenDistance(km));
                }
                else
                {
                    Console.WriteLine(truck.DrivenAGivenDistance(km));
                }
                break;

            case "Refuel":
                double liters = double.Parse(args[2]);
                if (type == "Car")
                {
                    car.RefueledVehicles(liters);
                }
                else
                {
                    truck.RefueledVehicles(liters);
                }
                break;
            }
        }
    }