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);
        }
Example #2
0
File: Engine.cs Project: mila89/OOP
        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}");
        }