Esempio n. 1
0
        static void Main()
        {
            string[] carInfo = Console.ReadLine().Split();
            Vehicle  car     = new Car(double.Parse(carInfo[1]), double.Parse(carInfo[2]), double.Parse(carInfo[3]));

            string[] truckInfo = Console.ReadLine().Split();
            Vehicle  truck     = new Truck(double.Parse(truckInfo[1]), double.Parse(truckInfo[2]), double.Parse(truckInfo[3]));

            string[] busInfo = Console.ReadLine().Split();
            Vehicle  bus     = new Bus(double.Parse(busInfo[1]), double.Parse(busInfo[2]), double.Parse(busInfo[3]));

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

            for (int i = 0; i < num; i++)
            {
                string[] info = Console.ReadLine().Split();
                try
                {
                    switch (info[0])
                    {
                    case "Drive":

                        if (info[1] == "Car")
                        {
                            Console.WriteLine(car.Distance(double.Parse(info[2])));
                        }
                        else if (info[1] == "Truck")
                        {
                            Console.WriteLine(truck.Distance(double.Parse(info[2])));
                        }
                        else if (info[1] == "Bus")
                        {
                            Console.WriteLine(bus.Distance(double.Parse(info[2]), true));
                        }
                        break;

                    case "DriveEmpty":

                        Console.WriteLine(bus.Distance(double.Parse(info[2])));
                        break;

                    case "Refuel":

                        if (info[1] == "Car")
                        {
                            car.Refuel(double.Parse(info[2]));
                        }
                        else if (info[1] == "Truck")
                        {
                            truck.Refuel(double.Parse(info[2]));
                        }
                        else if (info[1] == "Bus")
                        {
                            bus.Refuel(double.Parse(info[2]));
                        }
                        break;
                    }
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine(ae.Message);
                }
            }
            Console.WriteLine($"{car.ToString()}\n{truck.ToString()}\n{bus.ToString()}");
        }
Esempio n. 2
0
        static void Main()
        {
            string[] inputCar = Console.ReadLine().Split(' ');
            string[] inputTruck = Console.ReadLine().Split(' ');
            string[] inputBus = Console.ReadLine().Split(' ');
            double carFuelQty = double.Parse(inputCar[1]);
            double carfuelPerKM = double.Parse(inputCar[2]);
            double carfuelCapcity = double.Parse(inputCar[3]);
            Vehicle car = new Car(carFuelQty, carfuelPerKM, carfuelCapcity);

            double truckFuelQty = double.Parse(inputTruck[1]);
            double truckfuelPerKM = double.Parse(inputTruck[2]);
            double truckfuelCapacity = double.Parse(inputTruck[3]);
            Vehicle truck = new Truck(truckFuelQty, truckfuelPerKM, truckfuelCapacity);

            double busFuelQty = double.Parse(inputBus[1]);
            double busfuelPerKM = double.Parse(inputBus[2]);
            double busfuelCapacity = double.Parse(inputBus[3]);
            Vehicle bus = new Bus(busFuelQty, busfuelPerKM, busfuelCapacity);

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

            for (int i = 0; i < countOfCommands; i++)
            {
                string[] commands = Console.ReadLine().Split(' ');

                switch (commands[1])
                {
                    case "Car":
                    {
                        if (commands[0].Equals("Drive"))
                        {
                            double distance = double.Parse(commands[2]);
                            car.CanDriveGivenDistance(distance, "Car", true);
                        }
                        else
                        {
                            double fuel = double.Parse(commands[2]);
                            car.Refuel(fuel);
                        }
                        break;
                    }
                    case "Truck":
                    {
                        if (commands[0].Equals("Drive"))
                        {
                            double distance = double.Parse(commands[2]);
                            truck.CanDriveGivenDistance(distance, "Truck", true);
                        }
                        else
                        {
                            double fuel = double.Parse(commands[2]);
                            truck.Refuel(fuel);
                        }
                        break;
                    }
                    case "Bus":
                        {
                            if (commands[0].Equals("Drive"))
                            {
                                double distance = double.Parse(commands[2]);
                                bus.CanDriveGivenDistance(distance, "Bus", true);
                            }
                            else if (commands[0].Equals("DriveEmpty"))
                            {

                                double distance = double.Parse(commands[2]);
                                bus.CanDriveGivenDistance(distance, "Bus", false);
                            }
                            else
                            {
                                double fuel = double.Parse(commands[2]);
                                bus.Refuel(fuel);
                            }

                            break;
                        }

                }
            }
            Console.WriteLine("Car: {0:f2}",car.FuelQTY);
            Console.WriteLine("Truck: {0:f2}", truck.FuelQTY);
            Console.WriteLine("Bus: {0:f2}", bus.FuelQTY);
        }
Esempio n. 3
0
        static void Main()
        {
            try
            {
                var carInfo        = Console.ReadLine().Split();
                var carFuel        = double.Parse(carInfo[1]);
                var carLitersPerKm = double.Parse(carInfo[2]);
                var carTank        = double.Parse(carInfo[3]);
                var car            = new Car(carFuel, carLitersPerKm, carTank);

                var truckInfo        = Console.ReadLine().Split();
                var truckFuel        = double.Parse(truckInfo[1]);
                var truckLitersPerKm = double.Parse(truckInfo[2]);
                var truckTank        = double.Parse(truckInfo[3]);
                var truck            = new Truck(truckFuel, truckLitersPerKm, truckTank);

                var busInfo        = Console.ReadLine().Split();
                var busFuel        = double.Parse(busInfo[1]);
                var busLitersPerKm = double.Parse(busInfo[2]);
                var busTank        = double.Parse(busInfo[3]);
                var bus            = new Bus(busFuel, busLitersPerKm, busTank);

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

                for (int i = 0; i < commands; i++)
                {
                    var command     = Console.ReadLine().Split();
                    var action      = command[0];
                    var vehicleType = command[1];
                    var value       = double.Parse(command[2]);

                    switch (action)
                    {
                    case "Drive":
                        switch (vehicleType)
                        {
                        case "Car":
                            car.Drive(value);
                            break;

                        case "Truck":
                            truck.Drive(value);
                            break;

                        case "Bus":
                            bus.Drive(value);
                            break;
                        }
                        break;

                    case "Refuel":
                        switch (vehicleType)
                        {
                        case "Car":
                            car.Refuel(value);
                            break;

                        case "Truck":
                            truck.Refuel(value);
                            break;

                        case "Bus":
                            bus.Refuel(value);
                            break;
                        }
                        break;

                    case "DriveEmpty":
                        bus.DriveEmpty(value);
                        break;
                    }
                }

                Console.WriteLine($"Car: {car.Fuel:f2}");
                Console.WriteLine($"Truck: {truck.Fuel:f2}");
                Console.WriteLine($"Bus: {bus.Fuel:f2}");
            }
            catch (ArgumentException e)
            {
                Console.WriteLine(e.Message);
                throw;
            }
        }