Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            Car   car   = CreateCar(Console.ReadLine());
            Truck truck = CreatTruck(Console.ReadLine());
            Bus   bus   = CreatBus(Console.ReadLine());

            int numberOfCommands = int.Parse(Console.ReadLine());

            for (int i = 0; i < numberOfCommands; i++)
            {
                string[] command  = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
                string   action   = command[0];
                string   vechicle = command[1];
                double   value    = double.Parse(command[2]);
                try
                {
                    if (vechicle == "Car")
                    {
                        if (action == "Drive")
                        {
                            car.DriveDistance(value);
                        }
                        else if (action == "Refuel")
                        {
                            car.Refueld(value);
                        }
                    }
                    else if (vechicle == "Truck")
                    {
                        if (action == "Drive")
                        {
                            truck.DriveDistance(value);
                        }
                        else if (action == "Refuel")
                        {
                            truck.Refueld(value);
                        }
                    }
                    else if (vechicle == "Bus")
                    {
                        if (action == "Drive")
                        {
                            bus.DriveDistance(value);
                        }
                        else if (action == "Refuel")
                        {
                            bus.Refueld(value);
                        }
                        else if (action == "DriveEmpty")
                        {
                            bus.IsEmpty = true;
                            bus.DriveDistance(value);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            Console.WriteLine(car);
            Console.WriteLine(truck);
            Console.WriteLine(bus);
        }