Пример #1
0
        public static void Main()
        {
            string[] information     = Console.ReadLine().Split();
            double   fuelQuantity    = double.Parse(information[1]);
            double   fuelConsumption = double.Parse(information[2]);
            double   capacity        = double.Parse(information[3]);
            Car      car             = new Car(fuelQuantity, fuelConsumption, capacity);

            information     = Console.ReadLine().Split();
            fuelQuantity    = double.Parse(information[1]);
            fuelConsumption = double.Parse(information[2]);
            capacity        = double.Parse(information[3]);
            Truck truck = new Truck(fuelQuantity, fuelConsumption, capacity);

            information     = Console.ReadLine().Split();
            fuelQuantity    = double.Parse(information[1]);
            fuelConsumption = double.Parse(information[2]);
            capacity        = double.Parse(information[3]);
            Bus bus = new Bus(fuelQuantity, fuelConsumption, capacity);

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

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

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

                try
                {
                    switch (command)
                    {
                    case "Drive":
                        switch (vehicle)
                        {
                        case "Car":
                            Console.WriteLine(car.Drive(number)); break;

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

                        case "Bus":
                            Console.WriteLine(bus.Drive(number)); break;
                        }
                        break;

                    case "Refuel":
                        switch (vehicle)
                        {
                        case "Car":
                            car.AddFuel(number); break;

                        case "Truck":
                            truck.AddFuel(number); break;

                        case "Bus":
                            bus.AddFuel(number); break;
                        }
                        break;

                    case "DriveEmpty":
                        Console.WriteLine(bus.DriveEmpty(number));
                        break;
                    }
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine(ae.Message);
                }
            }

            Console.WriteLine(car);
            Console.WriteLine(truck);
            Console.WriteLine(bus);
        }
Пример #2
0
        public static void Main()
        {
            string[] carArgs = Console.ReadLine().Split();

            double carFuelQuantity    = double.Parse(carArgs[1]);
            double carFuelConsumption = double.Parse(carArgs[2]);
            int    carTankCapasity    = int.Parse(carArgs[3]);

            Car car = new Car(carFuelQuantity, carFuelConsumption, carTankCapasity);

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

            double truckFuelQuantity    = double.Parse(truckArgs[1]);
            double truckFuelConsumption = double.Parse(truckArgs[2]);
            int    truckTankCapasity    = int.Parse(truckArgs[3]);


            Truck truck = new Truck(truckFuelQuantity, truckFuelConsumption, truckTankCapasity);

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

            double busFuelQuantity    = double.Parse(busArgs[1]);
            double busFuelConsumption = double.Parse(busArgs[2]);
            int    busTankCapasity    = int.Parse(busArgs[3]);


            Bus bus = new Bus(busFuelQuantity, busFuelConsumption, busTankCapasity);


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

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

                string command     = commandArgs[0];
                string commandType = commandArgs[1];

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

                    if (commandType == "Car")
                    {
                        Console.WriteLine(car.Drive(distance));
                    }
                    else if (commandType == "Truck")
                    {
                        Console.WriteLine(truck.Drive(distance));
                    }
                    else
                    {
                        Console.WriteLine(bus.Drive(distance));
                    }
                }
                else if (command == "Refuel")
                {
                    double fuelAmount = double.Parse(commandArgs[2]);

                    try
                    {
                        if (commandType == "Car")
                        {
                            car.Refuel(fuelAmount);
                        }
                        else if (commandType == "Truck")
                        {
                            truck.Refuel(fuelAmount);
                        }
                        else
                        {
                            bus.Refuel(fuelAmount);
                        }
                    }
                    catch (Exception exception)
                    {
                        Console.WriteLine(exception.Message);
                    }
                }
                else
                {
                    double distance = double.Parse(commandArgs[2]);

                    Console.WriteLine(bus.DriveEmpty(distance));
                }
            }

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