Exemple #1
0
        public static void Main()
        {
            string[] information = Console.ReadLine().Split();
            Vehicle  car         = new Car(double.Parse(information[1]), double.Parse(information[2]), double.Parse(information[3]));

            information = Console.ReadLine().Split();
            Vehicle truck = new Truck(double.Parse(information[1]), double.Parse(information[2]), double.Parse(information[3]));

            information = Console.ReadLine().Split();
            Bus bus = new Bus(double.Parse(information[1]), double.Parse(information[2]), double.Parse(information[3]));

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

            for (int i = 0; i < lines; i++)
            {
                string[] command = Console.ReadLine().Split();

                if (command[0] == "Refuel")
                {
                    try
                    {
                        if (command[1] == "Car")
                        {
                            car.Refuel(double.Parse(command[2]));
                        }
                        else if (command[1] == "Truck")
                        {
                            truck.Refuel(double.Parse(command[2]));
                        }
                        else if (command[1] == "Bus")
                        {
                            bus.Refuel(double.Parse(command[2]));
                        }
                    }
                    catch (ArgumentException ae)
                    {
                        Console.WriteLine(ae.Message);
                    }
                }
                else if (command[0].Contains("Drive"))
                {
                    if (command[1] == "Car")
                    {
                        Console.WriteLine(car.Drive(double.Parse(command[2])));
                    }
                    else if (command[1] == "Truck")
                    {
                        Console.WriteLine(truck.Drive(double.Parse(command[2])));
                    }
                    else if (command[1] == "Bus")
                    {
                        if (command[0] == "Drive")
                        {
                            bus.TurnAirConditionerOn();
                            Console.WriteLine(bus.Drive(double.Parse(command[2])));
                        }
                        else if (command[0] == "DriveEmpty")
                        {
                            bus.TurnAirConditionerOff();
                            Console.WriteLine(bus.Drive(double.Parse(command[2])));
                        }
                    }
                }
            }

            Console.WriteLine(car);
            Console.WriteLine(truck);
            Console.WriteLine(bus);
        }
        static void Main(string[] args)
        {
            string[] data = Console.ReadLine().Split(" ");
            Vehicle  car  = new Car(double.Parse(data[1]), double.Parse(data[2]), double.Parse(data[3]));

            data = Console.ReadLine().Split(" ");
            Vehicle truck = new Truck(double.Parse(data[1]), double.Parse(data[2]), double.Parse(data[3]));

            data = Console.ReadLine().Split(" ");
            Vehicle bus = new Bus(double.Parse(data[1]), double.Parse(data[2]), double.Parse(data[3]));

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

            for (int i = 0; i < count; i++)
            {
                data = Console.ReadLine().Split(" ");
                string operation = data[0] + data[1];
                double value     = double.Parse(data[2]);
                try
                {
                    switch (operation)
                    {
                    case "DriveCar":
                        Console.WriteLine(car.Drive(value));
                        break;

                    case "DriveTruck":
                        Console.WriteLine(truck.Drive(value));
                        break;

                    case "DriveBus":
                        Console.WriteLine(bus.Drive(value));
                        break;

                    case "DriveEmptyBus":
                        var b = (Bus)bus;
                        b.TurnOffAirConditioner();
                        Console.WriteLine(b.Drive(value));
                        b.TurnOnAirConditioner();
                        break;

                    case "RefuelCar":
                        car.Refuel(value);
                        break;

                    case "RefuelTruck":
                        truck.Refuel(value);
                        break;

                    case "RefuelBus":
                        bus.Refuel(value);
                        break;

                    default:
                        break;
                    }
                }
                catch (ArgumentException exception)
                {
                    Console.WriteLine(exception.Message);
                }
            }

            Console.WriteLine(car.ToString());
            Console.WriteLine(truck.ToString());
            Console.WriteLine(bus.ToString());
        }
Exemple #3
0
        public static void Main(string[] args)
        {
            var carTokens = Console.ReadLine()
                            .Split(" ", StringSplitOptions.RemoveEmptyEntries);
            var car = new Car(double.Parse(carTokens[1]), double.Parse(carTokens[2]), double.Parse(carTokens[3]));

            var truckTokens = Console.ReadLine()
                              .Split(" ", StringSplitOptions.RemoveEmptyEntries);
            var truck = new Truck(double.Parse(truckTokens[1]), double.Parse(truckTokens[2]), double.Parse(truckTokens[3]));

            var busTokens = Console.ReadLine()
                            .Split(" ", StringSplitOptions.RemoveEmptyEntries);
            var bus = new Bus(double.Parse(busTokens[1]), double.Parse(busTokens[2]), double.Parse(busTokens[3]));

            var commandsCount = int.Parse(Console.ReadLine());

            for (int i = 0; i < commandsCount; i++)
            {
                var tokens = Console.ReadLine()
                             .Split(" ", StringSplitOptions.RemoveEmptyEntries);

                command     = tokens[0];
                vehicleType = tokens[1];
                var distanceOrAmount = double.Parse(tokens[2]);

                switch (command)
                {
                case "Drive":
                    if (vehicleType == "Car")
                    {
                        car.DriveVehicle(distanceOrAmount);
                    }
                    else if (vehicleType == "Truck")
                    {
                        truck.DriveVehicle(distanceOrAmount);
                    }
                    else if (vehicleType == "Bus")
                    {
                        bus.DriveVehicle(distanceOrAmount);
                    }
                    break;

                case "Refuel":
                    if (vehicleType == "Car")
                    {
                        car.RefuelVehicle(distanceOrAmount);
                    }
                    else if (vehicleType == "Truck")
                    {
                        truck.RefuelVehicle(distanceOrAmount);
                    }
                    else if (vehicleType == "Bus")
                    {
                        bus.RefuelVehicle(distanceOrAmount);
                    }
                    break;

                case "DriveEmpty":
                    if (vehicleType == "Bus")
                    {
                        bus.DriveVehicle(distanceOrAmount);
                    }
                    break;
                }
            }

            Console.WriteLine($"Car: {car.PrintLeftFuel():f2}");
            Console.WriteLine($"Truck: {truck.PrintLeftFuel():f2}");
            Console.WriteLine($"Bus: {bus.PrintLeftFuel():f2}");
        }
Exemple #4
0
        public static void Main(string[] args)
        {
            List <Vehicle> vehicles = new List <Vehicle>();

            //Vehicle {initial fuel quantity} {liters per km} {tank capacity}
            string[] carInfo         = Console.ReadLine().Split();
            double   carFuelQuantity = double.Parse(carInfo[1]);
            double   carLitersPerKm  = double.Parse(carInfo[2]);
            double   carTankCapacity = double.Parse(carInfo[3]);

            Vehicle car = new Car(carFuelQuantity, carLitersPerKm, carTankCapacity);

            vehicles.Add(car);

            string[] truckInfo         = Console.ReadLine().Split();
            double   truckFuelQuantity = double.Parse(truckInfo[1]);
            double   truckLitersPerKm  = double.Parse(truckInfo[2]);
            double   truckTankCapacity = double.Parse(truckInfo[3]);

            Vehicle truck = new Truck(truckFuelQuantity, truckLitersPerKm, truckTankCapacity);

            vehicles.Add(truck);

            string[] busInfo         = Console.ReadLine().Split();
            double   busFuelQuantity = double.Parse(busInfo[1]);
            double   busLitersPerKm  = double.Parse(busInfo[2]);
            double   busTankCapacity = double.Parse(busInfo[3]);

            Vehicle bus = new Bus(busFuelQuantity, busLitersPerKm, busTankCapacity);

            vehicles.Add(bus);

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

            for (int i = 0; i < n; i++)
            {
                string[] input       = Console.ReadLine().Split();
                string   command     = input[0];
                string   vehicleType = input[1];
                double   amount      = double.Parse(input[2]);

                if (command == "Refuel")
                {
                    if (vehicleType == "Car")
                    {
                        car.Refuel(amount);
                    }
                    else if (vehicleType == "Truck")
                    {
                        truck.Refuel(amount);
                    }
                    else if (vehicleType == "Bus")
                    {
                        bus.Refuel(amount);
                    }
                }
                else if (command == "Drive")
                {
                    if (vehicleType == "Car")
                    {
                        car.DistanceTravelled(amount);
                    }
                    else if (vehicleType == "Truck")
                    {
                        truck.DistanceTravelled(amount);
                    }
                    else if (vehicleType == "Bus")
                    {
                        bus.IsVehicleEmpty = false;
                        bus.DistanceTravelled(amount);
                    }
                }
                else if (command == "DriveEmpty")
                {
                    bus.IsVehicleEmpty = true;
                    bus.DistanceTravelled(amount);
                }
            }
            foreach (var vehicle in vehicles)
            {
                Console.WriteLine(vehicle);
            }
        }
Exemple #5
0
        public static void Main(string[] args)
        {
            string[] information = Console.ReadLine()
                                   .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            double  fuelQuantityCar = double.Parse(information[1]);
            double  consumptionCar  = double.Parse(information[2]);
            double  capacityTankCar = double.Parse(information[3]);
            Vehicle car             = new Car(fuelQuantityCar, consumptionCar, capacityTankCar);

            information = Console.ReadLine()
                          .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            double  fuelQuantityTruck = double.Parse(information[1]);
            double  consumptionTruck  = double.Parse(information[2]);
            double  capacityTankTruck = double.Parse(information[3]);
            Vehicle truck             = new Truck(fuelQuantityTruck, consumptionTruck, capacityTankTruck);

            information = Console.ReadLine()
                          .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            double  fuelQuantityBus = double.Parse(information[1]);
            double  consumptionBus  = double.Parse(information[2]);
            double  capacityTankBus = double.Parse(information[3]);
            Vehicle bus             = new Bus(fuelQuantityBus, consumptionBus, capacityTankBus);

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

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

                string action = command[0];
                string type   = command[1];
                double value  = double.Parse(command[2]);

                try
                {
                    if (type == "Car")
                    {
                        ImplementationCommand(car, action, value);
                    }
                    else if (type == "Truck")
                    {
                        ImplementationCommand(truck, action, value);
                    }
                    else if (type == "Bus")
                    {
                        if (action.EndsWith("Empty"))
                        {
                            ((Bus)bus).DriveEmpty();
                        }

                        ImplementationCommand(bus, action, value);
                    }
                }
                catch (ArgumentException exception)
                {
                    Console.WriteLine(exception.Message);
                }
            }

            Console.WriteLine(car);
            Console.WriteLine(truck);
            Console.WriteLine(bus);
        }
Exemple #6
0
        static void Main()
        {
            string[] carInfo   = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);
            Car      carEntity = new Car(double.Parse(carInfo[1]), double.Parse(carInfo[2]), double.Parse(carInfo[3]));

            string[] truckInfo   = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);
            Truck    truckEntity = new Truck(double.Parse(truckInfo[1]), double.Parse(truckInfo[2]), double.Parse(truckInfo[3]));

            string[] busInfo       = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);
            Bus      busEntity     = new Bus(double.Parse(busInfo[1]), double.Parse(busInfo[2]), double.Parse(busInfo[3]));
            int      commandNumber = int.Parse(Console.ReadLine());

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

                try
                {
                    if (input[0] == "Drive")
                    {
                        if (input[1] == "Car")
                        {
                            carEntity.Drive(double.Parse(input[2]));
                        }
                        else if (input[1] == "Truck")
                        {
                            truckEntity.Drive(double.Parse(input[2]));
                        }
                        else if (input[1] == "Bus")
                        {
                            busEntity.ACMod = 1.4d;
                            busEntity.Drive(double.Parse(input[2]));
                        }
                    }
                    else if (input[0] == "Refuel")
                    {
                        if (input[1] == "Car")
                        {
                            carEntity.Refuel(double.Parse(input[2]));
                        }
                        else if (input[1] == "Truck")
                        {
                            truckEntity.Refuel(double.Parse(input[2]));
                        }
                        else if (input[1] == "Bus")
                        {
                            truckEntity.Refuel(double.Parse(input[2]));
                        }
                    }
                    else if (input[0] == "DriveEmpty")
                    {
                        busEntity.ACMod = 0.0d;
                        busEntity.Drive(double.Parse(input[2]));
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            Console.WriteLine($"Car: {carEntity.FuelQuantity:f2}");
            Console.WriteLine($"Truck: {truckEntity.FuelQuantity:f2}");
            Console.WriteLine($"Bus: {busEntity.FuelQuantity:f2}");
        }
        static void Main(string[] args)
        {
            string[] carData = Console.ReadLine()
                               .Split(" ", StringSplitOptions.RemoveEmptyEntries)
                               .ToArray();
            string[] truckData = Console.ReadLine()
                                 .Split(" ", StringSplitOptions.RemoveEmptyEntries)
                                 .ToArray();
            string[] busData = Console.ReadLine()
                               .Split(" ", StringSplitOptions.RemoveEmptyEntries)
                               .ToArray();
            Vehicle car             = new Car(double.Parse(carData[1]), double.Parse(carData[2]), double.Parse(carData[3]));
            Vehicle truck           = new Truck(double.Parse(truckData[1]), double.Parse(truckData[2]), double.Parse(truckData[3]));
            Vehicle bus             = new Bus(double.Parse(busData[1]), double.Parse(busData[2]), double.Parse(busData[3]));
            int     numberOfCommand = int.Parse(Console.ReadLine());

            for (int i = 1; i <= numberOfCommand; i++)
            {
                string[] input = Console.ReadLine()
                                 .Split(" ", StringSplitOptions.RemoveEmptyEntries);
                var command  = input[0];
                var type     = input[1];
                var distance = double.Parse(input[2]);
                if (command == "Drive")
                {
                    if (type == "Car")
                    {
                        car.Driving(distance);
                    }
                    else if (type == "Truck")
                    {
                        truck.Driving(distance);
                    }
                    else if (type == "Bus")
                    {
                        bus.Driving(distance);
                    }
                }
                else if (command == "Refuel")
                {
                    if (type == "Car")
                    {
                        car.Refueling(distance);
                    }
                    else if (type == "Truck")
                    {
                        truck.Refueling(distance);
                    }
                    else if (type == "Bus")
                    {
                        bus.Refueling(distance);
                    }
                }
                else if (command == "DriveEmpty")
                {
                    if (type == "Bus")
                    {
                        ((Bus)bus).EmptyBus(distance);
                    }
                }
            }
            Console.WriteLine(car);
            Console.WriteLine(truck);
            Console.WriteLine(bus);
        }
Exemple #8
0
        static void Main(string[] args)
        {
            string[] carInfo = Console.ReadLine()
                               .Split(" ", StringSplitOptions.RemoveEmptyEntries);
            string[] truckInfo = Console.ReadLine()
                                 .Split(" ", StringSplitOptions.RemoveEmptyEntries);
            string[] busInfo = Console.ReadLine()
                               .Split(" ", StringSplitOptions.RemoveEmptyEntries);

            double carFuelQuantity    = double.Parse(carInfo[1]);
            double carFuelConsumption = double.Parse(carInfo[2]);
            double carTankCapacity    = double.Parse(carInfo[3]);

            double truckFuelQuantity    = double.Parse(truckInfo[1]);
            double truckFuelConsumption = double.Parse(truckInfo[2]);
            double truckTankCapacity    = double.Parse(truckInfo[3]);

            double busFuelQuantity    = double.Parse(busInfo[1]);
            double busFuelConsumption = double.Parse(busInfo[2]);
            double busTankCapacity    = double.Parse(busInfo[3]);

            Vehicle car   = new Car(carFuelQuantity, carFuelConsumption, carTankCapacity);
            Vehicle truck = new Truck(truckFuelQuantity, truckFuelConsumption, truckTankCapacity);
            Vehicle bus   = new Bus(busFuelQuantity, busFuelConsumption, busTankCapacity);

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

            for (int i = 0; i < numberOfOperations; i++)
            {
                string[] cmdArgs = Console.ReadLine()
                                   .Split(" ", StringSplitOptions.RemoveEmptyEntries);
                string option = cmdArgs[0];
                string type   = cmdArgs[1];
                double amount = double.Parse(cmdArgs[2]);

                if (option == "Drive" || option == "DriveEmpty")
                {
                    try
                    {
                        if (type == nameof(Car))
                        {
                            car.Drive(amount);
                        }
                        else if (type == nameof(Truck))
                        {
                            truck.Drive(amount);
                        }
                        else if (type == nameof(Bus) && option == "Drive")
                        {
                            bus.Drive(amount);
                        }
                        else if (type == nameof(Bus) && option == "DriveEmpty")
                        {
                            bus.DriveEmpty(amount);
                        }
                    }
                    catch (ArgumentException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                else if (option == "Refuel")
                {
                    if (type == nameof(Car))
                    {
                        car.Refuel(amount);
                    }
                    else if (type == nameof(Truck))
                    {
                        truck.Refuel(amount);
                    }
                    else if (type == nameof(Bus))
                    {
                        bus.Refuel(amount);
                    }
                }
            }

            Console.WriteLine($"Car: {car.FuelQuantity:f2}");
            Console.WriteLine($"Truck: {truck.FuelQuantity:f2}");
            Console.WriteLine($"Bus: {bus.FuelQuantity:f2}");
        }
        public static void Main()
        {
            var carInfo   = Console.ReadLine().Split();
            var truckInfo = Console.ReadLine().Split();
            var busInfo   = Console.ReadLine().Split();

            var car = new Car(double.Parse(carInfo[1]), double.Parse(carInfo[2]), double.Parse(carInfo[3]));

            var truck = new Truck(double.Parse(truckInfo[1]), double.Parse(truckInfo[2]), double.Parse(truckInfo[3]));

            var bus = new Bus(double.Parse(busInfo[1]), double.Parse(busInfo[2]), double.Parse(busInfo[3]));

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

            for (int i = 0; i < numberOfCommands; i++)
            {
                var commandInfo = Console.ReadLine().Split();

                var command = commandInfo[0];

                if (command == "Drive")
                {
                    if (commandInfo[1] == "Car")
                    {
                        car.Drive(double.Parse(commandInfo[2]));
                    }

                    else if (commandInfo[1] == "Truck")
                    {
                        truck.Drive(double.Parse(commandInfo[2]));
                    }

                    else if (commandInfo[1] == "Bus")
                    {
                        bus.ONAirConditioner();
                        bus.Drive(double.Parse(commandInfo[2]));
                        bus.OFFAirConditioner();
                    }
                }

                else if (command == "Refuel")
                {
                    if (commandInfo[1] == "Car")
                    {
                        car.Refuel(double.Parse(commandInfo[2]));
                    }

                    else if (commandInfo[1] == "Truck")
                    {
                        truck.Refuel(double.Parse(commandInfo[2]));
                    }

                    else if (commandInfo[1] == "Bus")
                    {
                        bus.Refuel(double.Parse(commandInfo[2]));
                    }
                }

                else if (command == "DriveEmpty")
                {
                    bus.Drive(double.Parse(commandInfo[2]));
                }
            }

            Console.WriteLine(car.ToString());
            Console.WriteLine(truck.ToString());
            Console.WriteLine(bus.ToString());
        }
Exemple #10
0
        public static void Main()
        {
            // "Vehicle {initial fuel quantity} {liters per km} {tank capacity}"
            List <Vehicle> vehicles = new List <Vehicle>();

            for (int i = 0; i < 3; i++)
            {
                string[] vehicleInfoArgs = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
                switch (vehicleInfoArgs[0])
                {
                case "Car":
                    var car = new Car(double.Parse(vehicleInfoArgs[1]),
                                      double.Parse(vehicleInfoArgs[2]),
                                      double.Parse(vehicleInfoArgs[3]));

                    vehicles.Add(car);
                    break;

                case "Truck":
                    var truck = new Truck(double.Parse(vehicleInfoArgs[1]),
                                          double.Parse(vehicleInfoArgs[2]),
                                          double.Parse(vehicleInfoArgs[3]));

                    vehicles.Add(truck);
                    break;

                case "Bus":
                    var bus = new Bus(double.Parse(vehicleInfoArgs[1]),
                                      double.Parse(vehicleInfoArgs[2]),
                                      double.Parse(vehicleInfoArgs[3]));

                    vehicles.Add(bus);
                    break;
                }
            }


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

            for (int i = 0; i < N; i++)
            {
                // read cmds
                string[] cmdArgs = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
                if (cmdArgs[0] == "Drive")
                {
                    try
                    {
                        double distance = double.Parse(cmdArgs[2]);
                        if (cmdArgs[1] == "Car")
                        {
                            vehicles.First(v => v.GetType().Name == "Car").Drive(distance);
                        }
                        else if (cmdArgs[1] == "Truck")
                        {
                            vehicles.First(v => v.GetType().Name == "Truck").Drive(distance);
                        }
                        else if (cmdArgs[1] == "Bus")
                        {
                            vehicles.First(v => v.GetType().Name == "Bus").Drive(distance);
                        }

                        Console.WriteLine($"{cmdArgs[1]} travelled {distance} km");
                    }
                    catch (ArgumentException ex)
                    {
                        Console.WriteLine(ex.Message);;
                    }
                }
                else if (cmdArgs[0] == "DriveEmpty")
                {
                    try
                    {
                        double distance = double.Parse(cmdArgs[2]);
                        var    bus      = vehicles.First(v => v.GetType().Name == "Bus") as Bus;
                        bus.IsEmpty = true;
                        bus.Drive(distance);// missing null check for bus

                        Console.WriteLine($"{cmdArgs[1]} travelled {distance} km");
                    }
                    catch (ArgumentException ex)
                    {
                        Console.WriteLine(ex.Message);;
                    }
                }
                else if (cmdArgs[0] == "Refuel")
                {
                    try
                    {
                        double liters = double.Parse(cmdArgs[2]);
                        if (cmdArgs[1] == "Car")
                        {
                            vehicles.First(v => v.GetType().Name == "Car").Refuel(liters);
                        }
                        else if (cmdArgs[1] == "Truck")
                        {
                            vehicles.First(v => v.GetType().Name == "Truck").Refuel(liters);
                        }
                        else if (cmdArgs[1] == "Bus")
                        {
                            vehicles.First(v => v.GetType().Name == "Bus").Refuel(liters);
                        }
                    }
                    catch (ArgumentException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }

            Console.WriteLine($"Car: {vehicles.First(v => v.GetType().Name == "Car").FuelQuantity:F2}");
            Console.WriteLine($"Truck: {vehicles.First(v => v.GetType().Name == "Truck").FuelQuantity:F2}");
            Console.WriteLine($"Bus: {vehicles.First(v => v.GetType().Name == "Bus").FuelQuantity:F2}");
        }
        public static void Main()
        {
            string[] carInfo = Console.ReadLine().Split();
            Vehicle  car     = new Car(double.Parse(carInfo[1]), double.Parse(carInfo[2]), double.Parse(carInfo[3]));

            string[] truckInfo = Console.ReadLine().Split();
            Vehicle  truck     = new Truck(double.Parse(truckInfo[1]), double.Parse(truckInfo[2]), double.Parse(truckInfo[3]));

            string[] busInfo = Console.ReadLine().Split();
            Vehicle  bus     = new Bus(double.Parse(busInfo[1]), double.Parse(busInfo[2]), double.Parse(busInfo[3]));

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

            for (int i = 0; i < n; i++)
            {
                string[] commandArr = Console.ReadLine().Split();

                try
                {
                    if (commandArr[1] == "Car")
                    {
                        if (commandArr[0] == "Drive")
                        {
                            Console.WriteLine(car.Drive(double.Parse(commandArr[2])));
                        }
                        else
                        {
                            car.Refuel(double.Parse(commandArr[2]));
                        }
                    }
                    else if (commandArr[1] == "Truck")
                    {
                        if (commandArr[0] == "Drive")
                        {
                            Console.WriteLine(truck.Drive(double.Parse(commandArr[2])));
                        }
                        else
                        {
                            truck.Refuel(double.Parse(commandArr[2]));
                        }
                    }
                    else
                    {
                        if (commandArr[0] == "Refuel")
                        {
                            bus.Refuel(double.Parse(commandArr[2]));
                        }
                        else
                        {
                            Console.WriteLine(((Bus)bus).Drive(double.Parse(commandArr[2]), commandArr[0]));
                        }
                    }
                }
                catch (ArgumentException argEx)
                {
                    Console.WriteLine(argEx.Message);
                }
            }

            Console.WriteLine($"Car: {car.FuelLef:F2}");
            Console.WriteLine($"Truck: {truck.FuelLef:F2}");
            Console.WriteLine($"Bus: {bus.FuelLef:F2}");
        }
Exemple #12
0
        public static void Main()
        {
            var car   = new Car(ParseData());
            var truck = new Truck(ParseData());
            var bus   = new Bus(ParseData());

            var linesCount = int.Parse(Console.ReadLine());

            for (int i = 0; i < linesCount; i++)
            {
                var commandArgs = Console.ReadLine().Split();

                var command = commandArgs[0];
                var type    = commandArgs[1];

                try
                {
                    if (command == "Drive")
                    {
                        var distance = double.Parse(commandArgs[2]);

                        if (type == "Car")
                        {
                            Console.WriteLine(car.Drive(distance));
                        }
                        else if (type == "Truck")
                        {
                            Console.WriteLine(truck.Drive(distance));
                        }
                        else
                        {
                            Console.WriteLine(bus.Drive(distance));
                        }
                    }
                    else if (command == "Refuel")
                    {
                        double fuel = double.Parse(commandArgs[2]);

                        if (type == "Car")
                        {
                            car.Refuel(fuel);
                        }
                        else if (type == "Truck")
                        {
                            truck.Refuel(fuel);
                        }
                        else
                        {
                            bus.Refuel(fuel);
                        }
                    }
                    else if (command == "DriveEmpty")
                    {
                        var distance = double.Parse(commandArgs[2]);
                        Console.WriteLine(bus.DriveEmpty(distance));
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            Console.WriteLine(car);
            Console.WriteLine(truck);
            Console.WriteLine(bus);
        }