Beispiel #1
0
        static void Main(string[] args)
        {
            var carInput   = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
            var truckInput = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);

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

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

            while (n > 0)
            {
                var commands = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);

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

                    case "Truck":
                        truck.DriveDistance(double.Parse(commands[2]));
                        break;

                    default:
                        break;
                    }
                    break;

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

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

                    default:
                        break;
                    }
                    break;
                }

                n--;
            }

            Console.WriteLine(car);
            Console.WriteLine(truck);
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            string[] inputCar   = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            string[] inputTruck = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

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

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

            for (int i = 0; i < num; i++)
            {
                string[] command  = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                double   comParam = double.Parse(command[2]);

                try
                {
                    switch (command[0].ToLower())
                    {
                    case "drive":
                        if (command[1].ToLower() == "car")
                        {
                            Console.WriteLine(car.DriveDistance(comParam));
                        }
                        else if (command[1].ToLower() == "truck")
                        {
                            Console.WriteLine(truck.DriveDistance(comParam));
                        }
                        break;

                    case "refuel":
                        if (command[1].ToLower() == "car")
                        {
                            car.ReFuel(comParam);
                        }
                        else if (command[1].ToLower() == "truck")
                        {
                            truck.ReFuel(comParam);
                        }
                        break;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }


            Console.WriteLine($"{car}\n{truck}");
        }
Beispiel #3
0
        public static void Main(string[] args)
        {
            Car   car   = CreateCar(Console.ReadLine());
            Truck truck = CreatTruck(Console.ReadLine());
            Bus   bus   = CreatBus(Console.ReadLine());

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

            for (int i = 0; i < numberOfCommands; i++)
            {
                string[] command  = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
                string   action   = command[0];
                string   vechicle = command[1];
                double   value    = double.Parse(command[2]);
                try
                {
                    if (vechicle == "Car")
                    {
                        if (action == "Drive")
                        {
                            car.DriveDistance(value);
                        }
                        else if (action == "Refuel")
                        {
                            car.Refueld(value);
                        }
                    }
                    else if (vechicle == "Truck")
                    {
                        if (action == "Drive")
                        {
                            truck.DriveDistance(value);
                        }
                        else if (action == "Refuel")
                        {
                            truck.Refueld(value);
                        }
                    }
                    else if (vechicle == "Bus")
                    {
                        if (action == "Drive")
                        {
                            bus.DriveDistance(value);
                        }
                        else if (action == "Refuel")
                        {
                            bus.Refueld(value);
                        }
                        else if (action == "DriveEmpty")
                        {
                            bus.IsEmpty = true;
                            bus.DriveDistance(value);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            Console.WriteLine(car);
            Console.WriteLine(truck);
            Console.WriteLine(bus);
        }