Example #1
0
        public static void Main()
        {
            double fuelQuantity;
            double fuelConsumption;

            var carInfo = Console.ReadLine().Split();

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

            var truckInfo = Console.ReadLine().Split();

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

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

            for (int i = 0; i < n; i++)
            {
                var commandArgs    = Console.ReadLine().Split();
                var command        = commandArgs[0];
                var carOrTruck     = commandArgs[1];
                var distanceOrFuel = double.Parse(commandArgs[2]);

                switch (command.ToLower())
                {
                case "drive":
                    switch (carOrTruck.ToLower())
                    {
                    case "car":
                        Console.WriteLine(car.Drive(distanceOrFuel));
                        break;

                    case "truck":
                        Console.WriteLine(truck.Drive(distanceOrFuel));
                        break;
                    }
                    break;

                case "refuel":
                    switch (carOrTruck.ToLower())
                    {
                    case "car":
                        car.Refuel(distanceOrFuel);
                        break;

                    case "truck":
                        truck.Refuel(distanceOrFuel);
                        break;
                    }
                    break;
                }
            }

            Console.WriteLine(car.ToString());
            Console.WriteLine(truck.ToString());
        }
Example #2
0
        public static void Main()
        {
            string         input    = Console.ReadLine();
            List <Vehicle> vehicles = new List <Vehicle>();

            string[] carDetails     = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            double   carFuel        = double.Parse(carDetails[1]);
            double   carConsumption = double.Parse(carDetails[2]);
            Vehicle  car            = new Car(carFuel, carConsumption);

            vehicles.Add(car);
            input = Console.ReadLine();

            string[] truckDetails     = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            double   truckFuel        = double.Parse(truckDetails[1]);
            double   truckConsumption = double.Parse(truckDetails[2]);
            Vehicle  truck            = new Truck(truckFuel, truckConsumption);

            vehicles.Add(truck);

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

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

                string command = splittedInput[0];
                string vehicle = splittedInput[1];
                double number  = double.Parse(splittedInput[2]);

                if (command == "Drive")
                {
                    if (vehicle == "Car")
                    {
                        car.Drive(number);
                    }
                    else
                    {
                        truck.Drive(number);
                    }
                }
                else
                {
                    if (vehicle == "Car")
                    {
                        car.Refuel(number);
                    }
                    else
                    {
                        truck.Refuel(number);
                    }
                }
            }

            Console.WriteLine(car);
            Console.WriteLine(truck);
        }
Example #3
0
        static void Main(string[] args)
        {
            string[] carInput          = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            double   litersQuantityCar = double.Parse(carInput[1]);
            double   litterPerKmCar    = double.Parse(carInput[2]);

            string[] truckInput          = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            double   litersQuantityTruck = double.Parse(truckInput[1]);
            double   litterPerKmTruck    = double.Parse(truckInput[2]);

            Car   car   = new Car(litersQuantityCar, litterPerKmCar);
            Truck truck = new Truck(litersQuantityTruck, litterPerKmTruck);

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

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

                string command = input[0].ToLower();
                string type    = input[1].ToLower();

                switch (command)
                {
                case "drive":
                    double distance = double.Parse(input[2]);
                    switch (type)
                    {
                    case "car":
                        car.Drive(distance);
                        break;

                    case "truck":
                        truck.Drive(distance);
                        break;
                    }
                    break;

                case "refuel":
                    double litters = double.Parse(input[2]);
                    switch (type)
                    {
                    case "car":
                        car.Refuel(litters);
                        break;

                    case "truck":
                        truck.Refuel(litters);
                        break;
                    }
                    break;
                }
            }
            Console.WriteLine(car);
            Console.WriteLine(truck);
        }
Example #4
0
        static void Main()
        {
            var carInput   = Console.ReadLine().Split();
            var truckInput = Console.ReadLine().Split();
            var busInput   = Console.ReadLine().Split();

            Vehicle car              = new Car(double.Parse(carInput[1]), double.Parse(carInput[2]), double.Parse(carInput[3]));
            Vehicle truck            = new Truck(double.Parse(truckInput[1]), double.Parse(truckInput[2]), double.Parse(truckInput[3]));
            Bus     bus              = new Bus(double.Parse(busInput[1]), double.Parse(busInput[2]), double.Parse(busInput[3]));
            int     numberOfCommands = int.Parse(Console.ReadLine());

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

                if (command[0].StartsWith('D'))
                {
                    if (command[0] == "DriveEmpty")
                    {
                        bus.DriveEmpty(double.Parse(command[2]));
                    }
                    else
                    {
                        if (command[1].StartsWith('C'))
                        {
                            car.Drive(double.Parse(command[2]));
                        }
                        else if (command[1].StartsWith('T'))
                        {
                            truck.Drive(double.Parse(command[2]));
                        }
                        else if (command[1].StartsWith('B'))
                        {
                            bus.Drive(double.Parse(command[2]));
                        }
                    }
                }
                else if (command[0].StartsWith('R'))
                {
                    if (command[1].StartsWith('C'))
                    {
                        car.Refuel(double.Parse(command[2]));
                    }
                    else if (command[1].StartsWith('T'))
                    {
                        truck.Refuel(double.Parse(command[2]));
                    }
                    else if (command[1].StartsWith('B'))
                    {
                        bus.Refuel(double.Parse(command[2]));
                    }
                }
            }

            Console.WriteLine($"Car: {car.fuelQuantity:f2}\nTruck: {truck.fuelQuantity:f2}\nBus: {bus.fuelQuantity:f2}");
        }
        private static void Execution(Car car, Truck truck, Bus bus, int n)
        {
            for (int i = 0; i < n; i++)
            {
                string[] commands    = Console.ReadLine().Split();
                string   command     = commands[0];
                string   typeVehicle = commands[1];

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

                    if (typeVehicle == "Car")
                    {
                        Console.WriteLine(car.Drive(distance));
                    }
                    else if (typeVehicle == "Truck")
                    {
                        Console.WriteLine(truck.Drive(distance));
                    }
                    else
                    {
                        Console.WriteLine(bus.Drive(distance));
                    }
                }
                else if (command == "Refuel")
                {
                    try
                    {
                        double refuelQuantity = double.Parse(commands[2]);

                        if (typeVehicle == "Car")
                        {
                            car.Refuel(refuelQuantity);
                        }
                        else if (typeVehicle == "Truck")
                        {
                            truck.Refuel(refuelQuantity);
                        }
                        else
                        {
                            bus.Refuel(refuelQuantity);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                else
                {
                    double distance = double.Parse(commands[2]);
                    Console.WriteLine(bus.DriveEmpty(distance));
                }
            }
        }
Example #6
0
        public static void Main()
        {
            string[] carArgs            = Console.ReadLine().Split().ToArray();
            double   carFuelQuantity    = double.Parse(carArgs[1]);
            double   carFuelConsumption = double.Parse(carArgs[2]);
            Vehicle  car = new Car(carFuelQuantity, carFuelConsumption);

            string[] truckArgs            = Console.ReadLine().Split().ToArray();
            double   truckFuelQuantity    = double.Parse(truckArgs[1]);
            double   truckFuelConsumption = double.Parse(truckArgs[2]);
            Vehicle  truck = new Truck(truckFuelQuantity, truckFuelConsumption);


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

            for (int i = 0; i < rotations; i++)
            {
                string[] commandArgs = Console.ReadLine().Split().ToArray();

                if (commandArgs[1] == "Car")
                {
                    if (commandArgs[0] == "Drive")
                    {
                        double distance = double.Parse(commandArgs[2]);
                        Console.WriteLine(car.Drive(distance));
                    }

                    else if (commandArgs[0] == "Refuel")
                    {
                        double fuelQuantity = double.Parse(commandArgs[2]);
                        car.Refuel(fuelQuantity);
                    }
                }

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

                    else if (commandArgs[0] == "Refuel")
                    {
                        double fuelQuantity = double.Parse(commandArgs[2]);
                        truck.Refuel(fuelQuantity);
                    }
                }
            }

            Console.WriteLine(car);
            Console.WriteLine(truck);
        }
Example #7
0
        static void Main(string[] args)
        {
            string[] carTokens = Console.ReadLine()
                                 .Split();
            double carFuel       = double.Parse(carTokens[1]);
            double carConsuption = double.Parse(carTokens[2]);

            string[] truckTokens = Console.ReadLine()
                                   .Split();
            double truckFuel       = double.Parse(truckTokens[1]);
            double truckConsuption = double.Parse(truckTokens[2]);

            Vehicle car   = new Car(carFuel, carConsuption);
            Vehicle truck = new Truck(truckFuel, truckConsuption);

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

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

                string vehicle  = input[1];
                string action   = input[0];
                double quantity = double.Parse(input[2]);

                if (vehicle == "Car")
                {
                    if (action == "Drive")
                    {
                        Console.WriteLine($"{car.Drive(quantity)}");
                    }
                    else
                    {
                        car.Refuel(quantity);
                    }
                }
                else
                {
                    if (action == "Drive")
                    {
                        Console.WriteLine($"{truck.Drive(quantity)}");
                    }
                    else
                    {
                        truck.Refuel(quantity);
                    }
                }
            }

            Console.WriteLine(car);
            Console.WriteLine(truck);
        }
Example #8
0
        static void Main(string[] args)
        {
            string[] carInfo   = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
            string[] truckInfo = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
            int      n         = int.Parse(Console.ReadLine());

            double  carFuel            = double.Parse(carInfo[1]);
            double  carFuelConsumption = double.Parse(carInfo[2]);
            Vehicle car = new Car(carFuel, carFuelConsumption);

            double  truckFuel            = double.Parse(truckInfo[1]);
            double  truckFuelConsumption = double.Parse(truckInfo[2]);
            Vehicle truck = new Truck(truckFuel, truckFuelConsumption);

            for (int i = 0; i < n; i++)
            {
                string[] cmdParts    = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
                string   command     = cmdParts[0];
                string   typeVehicle = cmdParts[1];

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

                    if (typeVehicle == "Car")
                    {
                        car.Drive(distance);
                    }
                    else
                    {
                        truck.Drive(distance);
                    }
                }
                else if (command == "Refuel")
                {
                    double fuel = double.Parse(cmdParts[2]);

                    if (typeVehicle == "Car")
                    {
                        car.Refuel(fuel);
                    }
                    else
                    {
                        truck.Refuel(fuel);
                    }
                }
            }

            Console.WriteLine($"Car: {car.FuelQuantity:F2}");
            Console.WriteLine($"Truck: {truck.FuelQuantity:F2}");
        }
Example #9
0
 private static void ExecuteRefuelCommand(string[] command, Car car, Truck truck, Bus bus)
 {
     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]));
     }
 }
Example #10
0
        private static void RefuelCommand(string[] commandParts)
        {
            string vehicle = commandParts[1];

            switch (vehicle)
            {
            case "Car":
                _car.Refuel(double.Parse(commandParts[2]));
                break;

            case "Truck":
                _truck.Refuel(double.Parse(commandParts[2]));
                break;
            }
        }
Example #11
0
        public static void Main()
        {
            string[] carInfo = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            Car      car     = new Car(double.Parse(carInfo[1]), double.Parse(carInfo[2]));

            string[] truckInfo = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            Truck    truck     = new Truck(double.Parse(truckInfo[1]), double.Parse(truckInfo[2]));

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

            for (int command = 0; command < totalCommands; command++)
            {
                string[] commandInfo = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                string   vehicleType = commandInfo[1];
                double   litters     = double.Parse(commandInfo[2]);

                switch (commandInfo[0])
                {
                case "Drive":
                    if (vehicleType == "Car")
                    {
                        Console.WriteLine(car.Drive(litters));
                    }
                    else if (vehicleType == "Truck")
                    {
                        Console.WriteLine(truck.Drive(litters));
                    }
                    break;

                case "Refuel":
                    if (vehicleType == "Car")
                    {
                        car.Refuel(litters);
                    }
                    else if (vehicleType == "Truck")
                    {
                        truck.Refuel(litters);
                    }
                    break;

                default:
                    break;
                }
            }

            Console.WriteLine($"Car: {car.FuelQuantity:f2}");
            Console.WriteLine($"Truck: {truck.FuelQuantity:f2}");
        }
Example #12
0
        static void Main()
        {
            string[] carInfo = Console.ReadLine().Split();
            Vehicle  car     = new Car(double.Parse(carInfo[1]), double.Parse(carInfo[2]));

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

            for (int i = 0; i < num; i++)
            {
                string[] info = Console.ReadLine().Split();
                switch (info[0])
                {
                case "Drive":
                    try
                    {
                        if (info[1] == "Car")
                        {
                            Console.WriteLine(car.Distance(double.Parse(info[2])));
                        }
                        else if (info[1] == "Truck")
                        {
                            Console.WriteLine(truck.Distance(double.Parse(info[2])));
                        }
                    }
                    catch (ArgumentException ae)
                    {
                        Console.WriteLine(ae.Message);
                    }
                    break;

                case "Refuel":

                    if (info[1] == "Car")
                    {
                        car.Refuel(double.Parse(info[2]));
                    }
                    else if (info[1] == "Truck")
                    {
                        truck.Refuel(double.Parse(info[2]));
                    }
                    break;
                }
            }
            Console.WriteLine($"{car.ToString()}\n{truck.ToString()}");
        }
Example #13
0
        static void Main(string[] args)
        {
            string[] carInput = Console.ReadLine().Split();

            Car car = new Car(double.Parse(carInput[1]), double.Parse(carInput[2]));

            string[] truckInput = Console.ReadLine().Split();

            Truck truck = new Truck(double.Parse(truckInput[1]), double.Parse(truckInput[2]));

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

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

                if (input[0] == "Drive")
                {
                    if (input[1] == "Car")
                    {
                        car.Drive(double.Parse(input[2]));
                    }
                    else if (input[1] == "Truck")
                    {
                        truck.Drive(double.Parse(input[2]));
                    }
                }

                if (input[0] == "Refuel")
                {
                    if (input[1] == "Car")
                    {
                        car.Refuel(double.Parse(input[2]));
                    }
                    else if (input[1] == "Truck")
                    {
                        truck.Refuel(double.Parse(input[2]));
                    }
                }
            }

            Console.WriteLine($"Car: {car.FuelQuantity:F2}");
            Console.WriteLine($"Truck: {truck.FuelQuantity:F2}");
        }
Example #14
0
        public static void Main()
        {
            var carInfo = Console.ReadLine().Split();

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

            var truckInfo = Console.ReadLine().Split();

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

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

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

                if (input[0] == "Drive")
                {
                    if (input[1] == "Car")
                    {
                        car.Drive(double.Parse(input[2]));
                    }
                    else
                    {
                        truck.Drive(double.Parse(input[2]));
                    }
                }
                else
                {
                    if (input[1] == "Car")
                    {
                        car.Refuel(double.Parse(input[2]));
                    }
                    else
                    {
                        truck.Refuel(double.Parse(input[2]));
                    }
                }
            }

            Console.WriteLine(car.ToString());
            Console.WriteLine(truck.ToString());
        }
Example #15
0
        static void Main()
        {
            var carArgs          = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var car              = new Car(double.Parse(carArgs[1]), double.Parse(carArgs[2]));
            var truckArgs        = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var truck            = new Truck(double.Parse(truckArgs[1]), double.Parse(truckArgs[2]));
            var numberOfCommands = int.Parse(Console.ReadLine());

            for (int i = 0; i < numberOfCommands; i++)
            {
                var cmdArgs = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                var cmd     = cmdArgs[0];
                var vehicle = cmdArgs[1];

                if (cmd == "Drive")
                {
                    if (vehicle == "Car")
                    {
                        car.Driving(double.Parse(cmdArgs[2]));
                    }
                    else
                    {
                        truck.Driving(double.Parse(cmdArgs[2]));
                    }
                }
                else if (cmd == "Refuel")
                {
                    if (vehicle == "Car")
                    {
                        car.Refuel(double.Parse(cmdArgs[2]));
                    }
                    else
                    {
                        truck.Refuel(double.Parse(cmdArgs[2]));
                    }
                }
            }

            Console.WriteLine($"Car: {car}");
            Console.WriteLine($"Truck: {truck}");
        }
Example #16
0
        private static void ExecuteCommands(Car car, Truck truck)
        {
            var numberOfCommands = int.Parse(Console.ReadLine());

            while (numberOfCommands > 0)
            {
                var command     = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                var action      = command[0];
                var vehicleType = command[1];
                var value       = double.Parse(command[2]);

                switch (action)
                {
                case "Drive":
                    Console.WriteLine(vehicleType == "Car" ? car.Drive(value) : truck.Drive(value));
                    break;

                case "Refuel":
                    switch (vehicleType)
                    {
                    case "Car":
                        car.Refuel(value);
                        break;

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

                    default:
                        break;
                    }
                    break;

                default:
                    break;
                }
                numberOfCommands--;
            }
        }
Example #17
0
        static void Main(string[] args)
        {
            string[] carInfo = Console.ReadLine()
                               .Split(" ");
            string[] truckInfo = Console.ReadLine()
                                 .Split(" ");

            Car   car   = new Car(double.Parse(carInfo[1]), double.Parse(carInfo[2]));
            Truck truck = new Truck(double.Parse(truckInfo[1]), double.Parse(truckInfo[2]));

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

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

                switch (commandElements[0])
                {
                case "Drive":
                    double distance = double.Parse(commandElements[2]);

                    switch (commandElements[1])
                    {
                    case "Car":
                        if (car.CanDrive(distance))
                        {
                            car.FuelQuantity -= distance * car.FuelConsumption;
                            Console.WriteLine($"Car travelled {distance} km");
                        }
                        else
                        {
                            Console.WriteLine("Car needs refueling");
                        }
                        break;

                    case "Truck":
                        if (truck.CanDrive(distance))
                        {
                            truck.FuelQuantity -= distance * truck.FuelConsumption;
                            Console.WriteLine($"Truck travelled {distance} km");
                        }
                        else
                        {
                            Console.WriteLine("Truck needs refueling");
                        }
                        break;
                    }
                    break;

                case "Refuel":
                    double fuelLiters = double.Parse(commandElements[2]);

                    switch (commandElements[1])
                    {
                    case "Car":
                        car.Refuel(fuelLiters);
                        break;

                    case "Truck":
                        truck.Refuel(fuelLiters);
                        break;
                    }
                    break;
                }
            }

            Console.WriteLine(car);
            Console.WriteLine(truck);
        }
Example #18
0
        static void Main()
        {
            try
            {
                var carInfo        = Console.ReadLine().Split();
                var carFuel        = double.Parse(carInfo[1]);
                var carLitersPerKm = double.Parse(carInfo[2]);
                var carTank        = double.Parse(carInfo[3]);
                var car            = new Car(carFuel, carLitersPerKm, carTank);

                var truckInfo        = Console.ReadLine().Split();
                var truckFuel        = double.Parse(truckInfo[1]);
                var truckLitersPerKm = double.Parse(truckInfo[2]);
                var truckTank        = double.Parse(truckInfo[3]);
                var truck            = new Truck(truckFuel, truckLitersPerKm, truckTank);

                var busInfo        = Console.ReadLine().Split();
                var busFuel        = double.Parse(busInfo[1]);
                var busLitersPerKm = double.Parse(busInfo[2]);
                var busTank        = double.Parse(busInfo[3]);
                var bus            = new Bus(busFuel, busLitersPerKm, busTank);

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

                for (int i = 0; i < commands; i++)
                {
                    var command     = Console.ReadLine().Split();
                    var action      = command[0];
                    var vehicleType = command[1];
                    var value       = double.Parse(command[2]);

                    switch (action)
                    {
                    case "Drive":
                        switch (vehicleType)
                        {
                        case "Car":
                            car.Drive(value);
                            break;

                        case "Truck":
                            truck.Drive(value);
                            break;

                        case "Bus":
                            bus.Drive(value);
                            break;
                        }
                        break;

                    case "Refuel":
                        switch (vehicleType)
                        {
                        case "Car":
                            car.Refuel(value);
                            break;

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

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

                    case "DriveEmpty":
                        bus.DriveEmpty(value);
                        break;
                    }
                }

                Console.WriteLine($"Car: {car.Fuel:f2}");
                Console.WriteLine($"Truck: {truck.Fuel:f2}");
                Console.WriteLine($"Bus: {bus.Fuel:f2}");
            }
            catch (ArgumentException e)
            {
                Console.WriteLine(e.Message);
                throw;
            }
        }
Example #19
0
        public static void Main()
        {
            string[] line1 = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            string[] line2 = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            string[] line3 = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            int      n     = int.Parse(Console.ReadLine());

            Car   car   = new Car(double.Parse(line1[1]), (double.Parse(line1[2]) + 0.9), double.Parse(line1[3]));
            Truck truck = new Truck(double.Parse(line2[1]), (double.Parse(line2[2]) + 1.6), double.Parse(line2[3]));
            Bus   bus   = new Bus(double.Parse(line3[1]), (double.Parse(line3[2]) + 1.4), double.Parse(line3[3]));

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

                    string command          = input[0];
                    string typeVehicle      = input[1];
                    double distanceOrLiters = double.Parse(input[2]);

                    switch (command)
                    {
                    case "Drive":
                        if (typeVehicle == "Car")
                        {
                            car.Drive(distanceOrLiters);
                        }
                        else if (typeVehicle == "Truck")
                        {
                            truck.Drive(distanceOrLiters);
                        }
                        else if (typeVehicle == "Bus")
                        {
                            bus.Drive(distanceOrLiters);
                        }

                        break;

                    case "Refuel":
                        if (typeVehicle == "Car")
                        {
                            car.Refuel(distanceOrLiters);
                        }
                        else if (typeVehicle == "Truck")
                        {
                            truck.Refuel(distanceOrLiters);
                        }
                        else if (typeVehicle == "Bus")
                        {
                            bus.Refuel(distanceOrLiters);
                        }

                        break;

                    case "DriveEmpty":
                        bus.DriveEmpty(distanceOrLiters);
                        break;

                    default: break;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            Console.WriteLine(car);
            Console.WriteLine(truck);
            Console.WriteLine(bus);
        }
Example #20
0
        static void Main()
        {
            string[] inputCar = Console.ReadLine().Split(' ');
            string[] inputTruck = Console.ReadLine().Split(' ');
            string[] inputBus = Console.ReadLine().Split(' ');
            double carFuelQty = double.Parse(inputCar[1]);
            double carfuelPerKM = double.Parse(inputCar[2]);
            double carfuelCapcity = double.Parse(inputCar[3]);
            Vehicle car = new Car(carFuelQty, carfuelPerKM, carfuelCapcity);

            double truckFuelQty = double.Parse(inputTruck[1]);
            double truckfuelPerKM = double.Parse(inputTruck[2]);
            double truckfuelCapacity = double.Parse(inputTruck[3]);
            Vehicle truck = new Truck(truckFuelQty, truckfuelPerKM, truckfuelCapacity);

            double busFuelQty = double.Parse(inputBus[1]);
            double busfuelPerKM = double.Parse(inputBus[2]);
            double busfuelCapacity = double.Parse(inputBus[3]);
            Vehicle bus = new Bus(busFuelQty, busfuelPerKM, busfuelCapacity);

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

            for (int i = 0; i < countOfCommands; i++)
            {
                string[] commands = Console.ReadLine().Split(' ');

                switch (commands[1])
                {
                    case "Car":
                    {
                        if (commands[0].Equals("Drive"))
                        {
                            double distance = double.Parse(commands[2]);
                            car.CanDriveGivenDistance(distance, "Car", true);
                        }
                        else
                        {
                            double fuel = double.Parse(commands[2]);
                            car.Refuel(fuel);
                        }
                        break;
                    }
                    case "Truck":
                    {
                        if (commands[0].Equals("Drive"))
                        {
                            double distance = double.Parse(commands[2]);
                            truck.CanDriveGivenDistance(distance, "Truck", true);
                        }
                        else
                        {
                            double fuel = double.Parse(commands[2]);
                            truck.Refuel(fuel);
                        }
                        break;
                    }
                    case "Bus":
                        {
                            if (commands[0].Equals("Drive"))
                            {
                                double distance = double.Parse(commands[2]);
                                bus.CanDriveGivenDistance(distance, "Bus", true);
                            }
                            else if (commands[0].Equals("DriveEmpty"))
                            {

                                double distance = double.Parse(commands[2]);
                                bus.CanDriveGivenDistance(distance, "Bus", false);
                            }
                            else
                            {
                                double fuel = double.Parse(commands[2]);
                                bus.Refuel(fuel);
                            }

                            break;
                        }

                }
            }
            Console.WriteLine("Car: {0:f2}",car.FuelQTY);
            Console.WriteLine("Truck: {0:f2}", truck.FuelQTY);
            Console.WriteLine("Bus: {0:f2}", bus.FuelQTY);
        }
        public static void Main()
        {
            try
            {
                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 N = int.Parse(Console.ReadLine());

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

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

                        case "Truck":
                            truck.Drive(distance);
                            break;

                        case "Bus":
                            bus.Drive(distance);
                            break;
                        }
                        break;

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

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

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

                    case "DriveEmpty":
                        distance             = double.Parse(command[2]);
                        bus.FuelConsumption -= 1.4;
                        bus.Drive(distance);
                        break;
                    }
                }

                Console.WriteLine("Car: {0:F2}", car.FuelQuantity);
                Console.WriteLine("Truck: {0:F2}", truck.FuelQuantity);
                Console.WriteLine("Bus: {0:F2}", bus.FuelQuantity);
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Example #22
0
        static void Main()
        {
            string[] inputCar       = Console.ReadLine().Split(' ');
            string[] inputTruck     = Console.ReadLine().Split(' ');
            string[] inputBus       = Console.ReadLine().Split(' ');
            double   carFuelQty     = double.Parse(inputCar[1]);
            double   carfuelPerKM   = double.Parse(inputCar[2]);
            double   carfuelCapcity = double.Parse(inputCar[3]);
            Vehicle  car            = new Car(carFuelQty, carfuelPerKM, carfuelCapcity);

            double  truckFuelQty      = double.Parse(inputTruck[1]);
            double  truckfuelPerKM    = double.Parse(inputTruck[2]);
            double  truckfuelCapacity = double.Parse(inputTruck[3]);
            Vehicle truck             = new Truck(truckFuelQty, truckfuelPerKM, truckfuelCapacity);

            double  busFuelQty      = double.Parse(inputBus[1]);
            double  busfuelPerKM    = double.Parse(inputBus[2]);
            double  busfuelCapacity = double.Parse(inputBus[3]);
            Vehicle bus             = new Bus(busFuelQty, busfuelPerKM, busfuelCapacity);


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

            for (int i = 0; i < countOfCommands; i++)
            {
                string[] commands = Console.ReadLine().Split(' ');

                switch (commands[1])
                {
                case "Car":
                {
                    if (commands[0].Equals("Drive"))
                    {
                        double distance = double.Parse(commands[2]);
                        car.CanDriveGivenDistance(distance, "Car", true);
                    }
                    else
                    {
                        double fuel = double.Parse(commands[2]);
                        car.Refuel(fuel);
                    }
                    break;
                }

                case "Truck":
                {
                    if (commands[0].Equals("Drive"))
                    {
                        double distance = double.Parse(commands[2]);
                        truck.CanDriveGivenDistance(distance, "Truck", true);
                    }
                    else
                    {
                        double fuel = double.Parse(commands[2]);
                        truck.Refuel(fuel);
                    }
                    break;
                }

                case "Bus":
                {
                    if (commands[0].Equals("Drive"))
                    {
                        double distance = double.Parse(commands[2]);
                        bus.CanDriveGivenDistance(distance, "Bus", true);
                    }
                    else if (commands[0].Equals("DriveEmpty"))
                    {
                        double distance = double.Parse(commands[2]);
                        bus.CanDriveGivenDistance(distance, "Bus", false);
                    }
                    else
                    {
                        double fuel = double.Parse(commands[2]);
                        bus.Refuel(fuel);
                    }

                    break;
                }
                }
            }
            Console.WriteLine("Car: {0:f2}", car.FuelQTY);
            Console.WriteLine("Truck: {0:f2}", truck.FuelQTY);
            Console.WriteLine("Bus: {0:f2}", bus.FuelQTY);
        }