private static void DriveVehicleCheck(Bus bus, Car car, Truck truck, string[] cmdInput, string type)
        {
            if (type == "Car")
            {
                double distance = double.Parse(cmdInput[2]);
                Console.WriteLine(car.Drive(distance));
            }

            else if (type == "Truck")
            {
                double distance = double.Parse(cmdInput[2]);
                Console.WriteLine(truck.Drive(distance));
            }

            else if (type == "Bus")
            {
                if (cmdInput[0] == "DriveEmpty")
                {
                    double emptyDistance = double.Parse(cmdInput[2]);
                    Console.WriteLine(bus.DriveEmpty(emptyDistance));
                }

                else if (cmdInput[0] == "Drive")
                {
                    double distance = double.Parse(cmdInput[2]);
                    Console.WriteLine(bus.Drive(distance));
                }
            }
        }
Beispiel #2
0
        private void ExecuteCommands()
        {
            string[] info = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);
            try
            {
                if (info[0].ToLower() == "drive" && info[1].ToLower() == "car")
                {
                    double km = double.Parse(info[2]);

                    Console.WriteLine(car.Drive(km));
                }
                else if (info[0].ToLower() == "drive" && info[1].ToLower() == "truck")
                {
                    double km = double.Parse(info[2]);

                    Console.WriteLine(truck.Drive(km));
                }
                else if (info[0].ToLower() == "drive" && info[1].ToLower() == "bus")
                {
                    double km = double.Parse(info[2]);

                    Console.WriteLine(bus.Drive(km));
                }
                else if (info[0].ToLower() == "driveempty" && info[1].ToLower() == "bus")
                {
                    double km = double.Parse(info[2]);

                    Console.WriteLine(bus.DriveEmpty(km));
                }
                else if (info[0].ToLower() == "refuel" && info[1].ToLower() == "car")
                {
                    double liters = double.Parse(info[2]);

                    car.Refuel(liters);
                }
                else if (info[0].ToLower() == "refuel" && info[1].ToLower() == "truck")
                {
                    double liters = double.Parse(info[2]);

                    truck.Refuel(liters);
                }
                else if (info[0].ToLower() == "refuel" && info[1].ToLower() == "bus")
                {
                    double liters = double.Parse(info[2]);

                    bus.Refuel(liters);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Beispiel #3
0
        public static void Main(string[] args)
        {
            var carInfo   = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var car       = new Car(double.Parse(carInfo[1]), double.Parse(carInfo[2]), int.Parse(carInfo[3]));
            var truckInfo = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var truck     = new Truck(double.Parse(truckInfo[1]), double.Parse(truckInfo[2]), int.Parse(truckInfo[3]));
            var busInfo   = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var bus       = new Bus(double.Parse(busInfo[1]), double.Parse(busInfo[2]), int.Parse(busInfo[3]));
            var n         = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                var input       = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                var command     = input[0];
                var vehicleType = input[1];
                if (command == "Drive")
                {
                    var km = double.Parse(input[2]);
                    switch (vehicleType)
                    {
                    case "Car": Console.WriteLine(car.Drive(km)); break;

                    case "Truck": Console.WriteLine(truck.Drive(km)); break;

                    case "Bus": bus.IsEmpty("Drive"); Console.WriteLine(bus.Drive(km)); break;
                    }
                }
                else if (command == "DriveEmpty")
                {
                    var km = double.Parse(input[2]);
                    bus.IsEmpty("DriveEmpty");
                    Console.WriteLine(bus.Drive(km));
                }
                else if (command == "Refuel")
                {
                    var fuel = double.Parse(input[2]);
                    switch (vehicleType)
                    {
                    case "Car": car.Refuel(fuel); break;

                    case "Truck": truck.Refuel(fuel); break;

                    case "Bus": bus.Refuel(fuel); break;
                    }
                }
            }

            Console.WriteLine(car);
            Console.WriteLine(truck);
            Console.WriteLine(bus);
        }
        public void Run()
        {
            var carInfo         = Console.ReadLine().Split();
            var carFuelQuantity = double.Parse(carInfo[1]);
            var carLitersPerKm  = double.Parse(carInfo[2]);
            var carTankCapacity = double.Parse(carInfo[3]);

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

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

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

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

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

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

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

                if (command[0] == "End")
                {
                    break;
                }
                else if (command[0] == "Drive" && command[1] == "Car")
                {
                    var kilometersToDrive = double.Parse(command[2]);
                    car.Drive(kilometersToDrive);
                }
                else if (command[0] == "Refuel" && command[1] == "Car")
                {
                    var fuel = double.Parse(command[2]);
                    car.Refuel(fuel);
                }
                else if (command[0] == "Drive" && command[1] == "Truck")
                {
                    var kilometersToDrive = double.Parse(command[2]);
                    truck.Drive(kilometersToDrive);
                }
                else if (command[0] == "Refuel" && command[1] == "Truck")
                {
                    var fuel = double.Parse(command[2]);
                    truck.Refuel(fuel);
                }
                else if (command[0] == "Drive" && command[1] == "Bus")
                {
                    var kilometersToDrive = double.Parse(command[2]);
                    bus.DriveWithPeople(kilometersToDrive);
                }
                else if (command[0] == "DriveEmpty")
                {
                    var kilometersToDrive = double.Parse(command[2]);
                    bus.Drive(kilometersToDrive);
                }
                else if (command[0] == "Refuel" && command[1] == "Bus")
                {
                    var fuel = double.Parse(command[2]);
                    bus.Refuel(fuel);
                }
            }
            Console.WriteLine($"Car: {car.FuelQuantity:f2}");
            Console.WriteLine($"Truck: {truck.FuelQuantity:f2}");
            Console.WriteLine($"Bus: {bus.FuelQuantity:f2}");
        }
Beispiel #5
0
        static void Main()
        {
            var carInfo = Console.ReadLine()
                          .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var truckInfo = Console.ReadLine()
                            .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var busInfo = Console.ReadLine()
                          .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);


            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 numberOfLines = int.Parse(Console.ReadLine());

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

                switch (command[0])
                {
                case "Drive":
                    switch (command[1])
                    {
                    case "Car":
                        car.Drive(double.Parse(command[2]));
                        break;

                    case "Truck":
                        truck.Drive(double.Parse(command[2]));
                        break;

                    case "Bus":
                        bus.Drive(double.Parse(command[2]), true);
                        break;
                    }
                    break;

                case "Refuel":
                    switch (command[1])
                    {
                    case "Car":
                        car.Refuel(double.Parse(command[2]));
                        break;

                    case "Truck":
                        truck.Refuel(double.Parse(command[2]));
                        break;

                    case "Bus":
                        bus.Refuel(double.Parse(command[2]));
                        break;
                    }
                    break;

                case "DriveEmpty":
                    bus.Drive(double.Parse(command[2]), false);
                    break;
                }
            }

            Console.WriteLine($"Car: {car.FuelQuantity:F2}");
            Console.WriteLine($"Truck: {truck.FuelQuantity:F2}");
            Console.WriteLine($"Bus: {bus.FuelQuantity:F2}");
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            Car   car   = new Car();
            Truck truck = new Truck();
            Bus   bus   = new Bus();

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

                if (input[0] == "Car")
                {
                    car.FuelConsumption = double.Parse(input[2]);
                    car.TankCapacity    = int.Parse(input[3]);
                    car.FuelQuantity    = double.Parse(input[1]);
                }
                else if (input[0] == "Truck")
                {
                    truck.FuelConsumption = double.Parse(input[2]);
                    truck.TankCapacity    = int.Parse(input[3]);
                    truck.FuelQuantity    = double.Parse(input[1]);
                }
                else if (input[0] == "Bus")
                {
                    bus.FuelConsumption = double.Parse(input[2]);
                    bus.TankCapacity    = int.Parse(input[3]);
                    bus.FuelQuantity    = double.Parse(input[1]);
                }
            }

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


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

                if (vehicle == "Car")
                {
                    if (command == "Drive")
                    {
                        car.Drive(parameter);
                    }
                    else if (command == "Refuel")
                    {
                        car.Refuel(parameter);
                    }
                }
                else if (vehicle == "Truck")
                {
                    if (command == "Drive")
                    {
                        truck.Drive(parameter);
                    }
                    else if (command == "Refuel")
                    {
                        truck.Refuel(parameter);
                    }
                }
                else if (vehicle == "Bus")
                {
                    if (command == "Drive")
                    {
                        bus.Drive(parameter);
                    }
                    else if (command == "DriveEmpty")
                    {
                        bus.Drive(parameter, true);
                    }
                    else if (command == "Refuel")
                    {
                        bus.Refuel(parameter);
                    }
                }
            }

            Console.WriteLine($"Car: {car.FuelQuantity:F2}");
            Console.WriteLine($"Truck: {truck.FuelQuantity:F2}");
            Console.WriteLine($"Bus: {bus.FuelQuantity:F2}");
        }
Beispiel #7
0
        public static void Main()
        {
            string[] carArgs = Console.ReadLine()
                               .Split();
            string[] truckArgs = Console.ReadLine()
                                 .Split();
            string[] busArgs = Console.ReadLine()
                               .Split();

            Car   car   = new Car(double.Parse(carArgs[1]), double.Parse(carArgs[2]), double.Parse(carArgs[3]));
            Truck truck = new Truck(double.Parse(truckArgs[1]), double.Parse(truckArgs[2]), double.Parse(truckArgs[3]));
            Bus   bus   = new Bus(double.Parse(busArgs[1]), double.Parse(busArgs[2]), double.Parse(busArgs[3]));

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

            for (int i = 0; i < count; i++)
            {
                try
                {
                    string[] inputArgs = Console.ReadLine()
                                         .Split();

                    string command          = inputArgs[0];
                    string vehicleType      = inputArgs[1];
                    double distanceOrLiters = double.Parse(inputArgs[2]);

                    if (command == "Drive")
                    {
                        if (vehicleType == "Car")
                        {
                            Console.WriteLine(car.Drive(distanceOrLiters));
                        }
                        else if (vehicleType == "Truck")
                        {
                            Console.WriteLine(truck.Drive(distanceOrLiters));
                        }
                        else if (vehicleType == "Bus")
                        {
                            bus.IsEmpty = false;
                            Console.WriteLine(bus.Drive(distanceOrLiters));
                        }
                    }
                    else if (command == "Refuel")
                    {
                        if (vehicleType == "Car")
                        {
                            car.Refuel(distanceOrLiters);
                        }
                        else if (vehicleType == "Truck")
                        {
                            truck.Refuel(distanceOrLiters);
                        }
                        else if (vehicleType == "Bus")
                        {
                            bus.Refuel(distanceOrLiters);
                        }
                    }
                    else if (command == "DriveEmpty")
                    {
                        bus.IsEmpty = true;
                        Console.WriteLine(bus.Drive(distanceOrLiters));
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            Console.WriteLine(car);
            Console.WriteLine(truck);
            Console.WriteLine(bus);
        }
Beispiel #8
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());
        }
Beispiel #10
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}");
        }
Beispiel #11
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());
        }
        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}");
        }
Beispiel #14
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);
        }