Example #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);
        }
Example #2
0
        static void Main(string[] args)
        {
            var carInfo          = Console.ReadLine().Split();
            var carFuel          = double.Parse(carInfo[1]);
            var carConsumption   = double.Parse(carInfo[2]);
            var carTank          = double.Parse(carInfo[3]);
            var car              = new Car(carFuel, carConsumption, carTank);
            var truckInfo        = Console.ReadLine().Split();
            var truckFuel        = double.Parse(truckInfo[1]);
            var truckConsumption = double.Parse(truckInfo[2]);
            var truckTank        = double.Parse(truckInfo[3]);
            var truck            = new Truck(truckFuel, truckConsumption, truckTank);
            var busInfo          = Console.ReadLine().Split();
            var busFuel          = double.Parse(busInfo[1]);
            var busConsumption   = double.Parse(busInfo[2]);
            var busTank          = double.Parse(busInfo[3]);
            var bus              = new Bus(busFuel, busConsumption, busTank);

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

            for (int i = 0; i < n; i++)
            {
                var currentInput = Console.ReadLine().Split();
                var command      = currentInput[0];
                var vehicle      = currentInput[1];

                if (command == "Drive")
                {
                    var distance = double.Parse(currentInput[2]);
                    if (vehicle == "Car")
                    {
                        Console.WriteLine(car.Drive(distance));
                    }
                    else if (vehicle == "Truck")
                    {
                        Console.WriteLine(truck.Drive(distance));
                    }
                    else if (vehicle == "Bus")
                    {
                        Console.WriteLine(bus.DriveNotEmpty(distance));
                    }
                }
                else if (command == "DriveEmpty")
                {
                    var distance = double.Parse(currentInput[2]);

                    Console.WriteLine(bus.Drive(distance));
                }
                else if (command == "Refuel")
                {
                    var fuel = double.Parse(currentInput[2]);
                    if (vehicle == "Car")
                    {
                        try
                        {
                            car.Refuel(fuel);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                    else if (vehicle == "Truck")
                    {
                        try
                        {
                            truck.Refuel(fuel);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                    else if (vehicle == "Bus")
                    {
                        try
                        {
                            bus.Refuel(fuel);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                }
            }

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