static void Main(string[] args)
        {
            string[] carData = Console.ReadLine()
                               .Split(" ", StringSplitOptions.RemoveEmptyEntries)
                               .ToArray();
            string[] truckData = Console.ReadLine()
                                 .Split(" ", StringSplitOptions.RemoveEmptyEntries)
                                 .ToArray();
            Vehicle car             = new Car(double.Parse(carData[1]), double.Parse(carData[2]));
            Vehicle truck           = new Truck(double.Parse(truckData[1]), double.Parse(truckData[2]));
            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
                    {
                        truck.Driving(distance);
                    }
                }
                else
                {
                    if (type == "Car")
                    {
                        car.Refueling(distance);
                    }
                    else
                    {
                        truck.Refueling(distance);
                    }
                }
            }
            Console.WriteLine(car);
            Console.WriteLine(truck);
        }
Exemple #2
0
        public void Run()
        {
            string[] inputCar     = Console.ReadLine().Split();
            string[] inputTruck   = Console.ReadLine().Split();
            Vehicles currentCar   = new Car(double.Parse(inputCar[1]), double.Parse(inputCar[2]));
            Vehicles currentTruck = new Truck(double.Parse(inputTruck[1]), double.Parse(inputTruck[2]));
            int      n            = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                string[] command = Console.ReadLine().Split();
                if (command[1] == "Car")
                {
                    if (command[0] == "Drive")
                    {
                        currentCar.Driving(double.Parse(command[2]));
                    }
                    else if (command[0] == "Refuel")
                    {
                        currentCar.Refueling(double.Parse(command[2]));
                    }
                }
                else if (command[1] == "Truck")
                {
                    if (command[0] == "Drive")
                    {
                        currentTruck.Driving(double.Parse(command[2]));
                    }
                    else if (command[0] == "Refuel")
                    {
                        currentTruck.Refueling(double.Parse(command[2]));
                    }
                }
            }
            Console.WriteLine($"Car: {Math.Round(currentCar.Quantity, 2, MidpointRounding.AwayFromZero):f2}");
            Console.WriteLine($"Truck: {Math.Round(currentTruck.Quantity, 2, MidpointRounding.AwayFromZero):f2}");
        }
        static void Main(string[] args)
        {
            string[] inputCar = Console.ReadLine().Split();
            Car      car      = new Car(double.Parse(inputCar[1]), double.Parse(inputCar[2]));

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

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

            for (int i = 0; i < numberOfCommands; i++)
            {
                string[] commands       = Console.ReadLine().Split();
                string   currentCommand = commands[0] + " " + commands[1];
                double   currentNum     = double.Parse(commands[2]);

                if (currentCommand == "Drive Car")
                {
                    Console.WriteLine(car.Driving(currentNum));
                }
                else if (currentCommand == "Drive Truck")
                {
                    Console.WriteLine(truck.Driving(currentNum));
                }
                else if (currentCommand == "Refuel Car")
                {
                    car.Refuel(currentNum);
                }
                else if (currentCommand == "Refuel Truck")
                {
                    truck.Refuel(currentNum);
                }
            }

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