Exemple #1
0
        public static void Main()
        {
            string[] carInformation     = Console.ReadLine().Split();
            double   carFuelQuantity    = double.Parse(carInformation[1]);
            double   carFuelConsumption = double.Parse(carInformation[2]);
            int      carTankCapacity    = int.Parse(carInformation[3]);

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

            string[] truckInformation     = Console.ReadLine().Split();
            double   truckFuelQuantity    = double.Parse(truckInformation[1]);
            double   truckFuelConsumption = double.Parse(truckInformation[2]);
            int      truckTankCapacity    = int.Parse(truckInformation[3]);

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

            string[] busInformation     = Console.ReadLine().Split();
            double   busFuelQuantity    = double.Parse(busInformation[1]);
            double   busFuelConsumption = double.Parse(busInformation[2]);
            int      busTankCapacity    = int.Parse(busInformation[3]);

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

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

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

                if (input[0] == "Drive")
                {
                    double distance = double.Parse(input[2]);
                    if (input[1] == "Car")
                    {
                        Console.WriteLine(car.Drive(distance));
                    }
                    else if (input[1] == "Truck")
                    {
                        Console.WriteLine(truck.Drive(distance));
                    }
                    else
                    {
                        Console.WriteLine(bus.Drive(distance));
                    }
                }
                else if (input[0] == "Refuel")
                {
                    double liters = double.Parse(input[2]);

                    try
                    {
                        if (input[1] == "Car")
                        {
                            car.Refuel(liters);
                        }
                        else if (input[1] == "Truck")
                        {
                            truck.Refuel(liters);
                        }
                        else
                        {
                            bus.Refuel(liters);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                else
                {
                    double distance = double.Parse(input[2]);
                    Console.WriteLine(bus.DriveEmpty(distance));
                }
            }

            Console.WriteLine(car);
            Console.WriteLine(truck);
            Console.WriteLine(bus);
        }
Exemple #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);
        }
Exemple #3
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);
        }
Exemple #4
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);
            }
        }