示例#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
        static void Main(string[] args)
        {
            List <Vehicle> vehicles = new List <Vehicle>();

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

                double fuelQuantity    = double.Parse(vehicleArgs[1]);
                double fuelConsumption = double.Parse(vehicleArgs[2]);
                int    tankCapacity    = int.Parse(vehicleArgs[3]);

                Vehicle vehicle = null;

                if (i == 0)
                {
                    vehicle = new Car(fuelQuantity, fuelConsumption, tankCapacity);
                }
                else if (i == 1)
                {
                    vehicle = new Truck(fuelQuantity, fuelConsumption, tankCapacity);
                }
                else
                {
                    vehicle = new Bus(fuelQuantity, fuelConsumption, tankCapacity);
                }

                vehicles.Add(vehicle);
            }

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

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

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

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

                    Vehicle currentVehicle = vehicles
                                             .FirstOrDefault(x => x.GetType().Name == commandType);

                    Console.WriteLine(currentVehicle.Drive(distance));
                }
                else if (command == "Refuel")
                {
                    double fuelAmount = double.Parse(commandArgs[2]);

                    Vehicle currentVehicle = vehicles
                                             .FirstOrDefault(x => x.GetType().Name == commandType);

                    try
                    {
                        currentVehicle.Refuel(fuelAmount);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                else
                {
                    double distance = double.Parse(commandArgs[2]);

                    Bus currentBus = (Bus)vehicles
                                     .FirstOrDefault(x => x.GetType().Name == commandType);

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

            foreach (var vehicle in vehicles)
            {
                Console.WriteLine(vehicle);
            }
        }
示例#3
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);
        }
        static void Main()
        {
            string[] carInfo = Console.ReadLine().Split();

            double carFuelQuantity = double.Parse(carInfo[1]);
            double carLitersPerKm  = double.Parse(carInfo[2]);
            double carTankCapacity = double.Parse(carInfo[3]);

            Vehicle car = new Car(carFuelQuantity, carLitersPerKm, carTankCapacity);

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

            double truckFuelQuantity = double.Parse(truckInfo[1]);
            double truckLitersPerKm  = double.Parse(truckInfo[2]);
            double truckTankCapacity = double.Parse(truckInfo[3]);

            Vehicle truck = new Truck(truckFuelQuantity, truckLitersPerKm, truckTankCapacity);

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

            double busFuelQuantity = double.Parse(busInfo[1]);
            double busLitersPerKm  = double.Parse(busInfo[2]);
            double busTankCapacity = double.Parse(busInfo[3]);

            Vehicle bus = new Bus(busFuelQuantity, busLitersPerKm, busTankCapacity);

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

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

                string vehicleType = commandArgs[1];
                string command     = commandArgs[0];
                double amount      = double.Parse(commandArgs[2]);

                try
                {
                    switch (vehicleType)
                    {
                    case "Car":
                        ExecuteCommand(car, command, amount);
                        break;

                    case "Truck":
                        ExecuteCommand(truck, command, amount);
                        break;

                    case "Bus":
                        ExecuteCommand(bus, command, amount);
                        break;
                    }
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            PrintRemainingFuel(car, truck, bus);
        }