예제 #1
0
        public void Run()
        {
            string[] carInfo   = Console.ReadLine().Split();
            string[] truckInfo = Console.ReadLine().Split();
            string[] busInfo   = Console.ReadLine().Split();

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

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

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

            IVehicle car   = new Car(carFuelQuantity, carFuelConsumption, carTankCapacity);
            IVehicle truck = new Truck(truckFuelQuantity, truckFuelConsumption, truckTankCapacity);
            IVehicle bus   = new Bus(busFuelQuantity, busFuelConsumption, busTankCapacity);

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

            for (int i = 0; i < n; i++)
            {
                string[] vehicleInfo  = Console.ReadLine().Split();
                string   actionType   = vehicleInfo[0];
                string   vehicleType  = vehicleInfo[1];
                double   vehicleValue = double.Parse(vehicleInfo[2]);

                if (actionType.ToLower() == "refuel")
                {
                    try
                    {
                        if (vehicleType.ToLower() == "car")
                        {
                            car.Refuel(vehicleValue);
                        }
                        else if (vehicleType.ToLower() == "truck")
                        {
                            truck.Refuel(vehicleValue);
                        }
                        else
                        {
                            bus.Refuel(vehicleValue);
                        }
                    }
                    catch (ArgumentException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                else if (actionType.ToLower() == "drive" || actionType.ToLower() == "driveempty")
                {
                    try
                    {
                        if (vehicleType.ToLower() == "car")
                        {
                            car.Drive(vehicleValue);
                        }
                        else if (vehicleType.ToLower() == "truck")
                        {
                            truck.Drive(vehicleValue);
                        }
                        else
                        {
                            if (actionType.ToLower() == "drive")
                            {
                                bus.IsVehicleEmpty = false;
                            }
                            else
                            {
                                bus.IsVehicleEmpty = true;
                            }
                            bus.Drive(vehicleValue);
                        }
                    }
                    catch (ArgumentException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }

            Console.WriteLine(car);
            Console.WriteLine(truck);
            Console.WriteLine(bus);
        }
예제 #2
0
        public void Run()
        {
            var carInfo = Console.ReadLine()
                          .Split();

            var truckInfo = Console.ReadLine()
                            .Split();

            var busInfo = Console.ReadLine()
                          .Split();

            var carFuelQuantity    = double.Parse(carInfo[1]);
            var carFuelConsuptnion = double.Parse(carInfo[2]);
            var carTankCapasity    = double.Parse(carInfo[3]);

            var truckFuelQuantity    = double.Parse(truckInfo[1]);
            var truckFuelConsuptnion = double.Parse(truckInfo[2]);
            var truckTankCapasity    = double.Parse(truckInfo[3]);

            var busFuelQuantity    = double.Parse(busInfo[1]);
            var busFuelConsuptnion = double.Parse(busInfo[2]);
            var busTankCapasity    = double.Parse(busInfo[3]);

            var car   = new Car(carFuelQuantity, carFuelConsuptnion, carTankCapasity);
            var truck = new Truck(truckFuelQuantity, truckFuelConsuptnion, truckTankCapasity);
            var bus   = new Bus(busFuelQuantity, busFuelConsuptnion, busTankCapasity);

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

            for (int i = 0; i < count; i++)
            {
                try
                {
                    var inputInfo = Console.ReadLine()
                                    .Split();

                    var command = inputInfo[0];
                    var type    = inputInfo[1];
                    var value   = double.Parse(inputInfo[2]);

                    if (command == "Drive")
                    {
                        if (type == "Car")
                        {
                            DriveVehicle(car, value);
                        }
                        else if (type == "Truck")
                        {
                            DriveVehicle(truck, value);
                        }
                        else if (type == "Bus")
                        {
                            bus.IsEmpty = false;
                            DriveVehicle(bus, value);
                        }
                    }
                    else if (command == "Refuel")
                    {
                        if (type == "Car")
                        {
                            car.Refuel(value);
                        }
                        else if (type == "Truck")
                        {
                            truck.Refuel(value);
                        }
                        else if (type == "Bus")
                        {
                            bus.Refuel(value);
                        }
                    }
                    else if (command == "DriveEmpty")
                    {
                        bus.IsEmpty = true;
                        DriveVehicle(bus, value);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            Console.WriteLine($"Car: {car.FuelQUantity:f2}");
            Console.WriteLine($"Truck: {truck.FuelQUantity:f2}");
            Console.WriteLine($"Bus: {bus.FuelQUantity:f2}");
        }
예제 #3
0
        public void Run()
        {
            string[] carInfo = Console.ReadLine().Split();
            IVehicle car     = new Car(double.Parse(carInfo[1]), double.Parse(carInfo[2]), double.Parse(carInfo[3]));

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

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


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

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

                string command = commandsArrgs[0];
                string vehicle = commandsArrgs[1];

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

                        if (vehicle == "Car")
                        {
                            car.Drive(distance);
                        }
                        else if (vehicle == "Truck")
                        {
                            truck.Drive(distance);
                        }
                        else if (vehicle == "Bus")
                        {
                            bus.isVehicleEmpty = false;
                            bus.Drive(distance);
                        }
                    }
                    else if (command == "Refuel")
                    {
                        double fuel = double.Parse(commandsArrgs[2]);

                        if (vehicle == "Car")
                        {
                            car.Refuel(fuel);
                        }
                        else if (vehicle == "Truck")
                        {
                            truck.Refuel(fuel);
                        }
                        else if (vehicle == "Bus")
                        {
                            bus.Refuel(fuel);
                        }
                    }
                    else if (command == "DriveEmpty")
                    {
                        double distance = double.Parse(commandsArrgs[2]);
                        bus.isVehicleEmpty = true;
                        bus.Drive(distance);
                    }
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            Console.WriteLine(car);
            Console.WriteLine(truck);
            Console.WriteLine(bus);
        }
예제 #4
0
        public void Run()
        {
            string[] carInfo = Console.ReadLine()
                               .Split()
                               .ToArray();

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

            double carFuelQuantity    = double.Parse(carInfo[1]);
            double carFuelConsumption = double.Parse(carInfo[2]);

            double truckFuelQuantity    = double.Parse(truckInfo[1]);
            double truckFuelConsumption = double.Parse(truckInfo[2]);

            Car   car   = new Car(carFuelQuantity, carFuelConsumption);
            Truck truck = new Truck(truckFuelQuantity, truckFuelConsumption);

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

            for (int i = 0; i < n; i++)
            {
                string[] inputInfo = Console.ReadLine()
                                     .Split()
                                     .ToArray();

                string command     = inputInfo[0];
                string vehicleType = inputInfo[1];
                double value       = double.Parse(inputInfo[2]);

                if (command == "Drive")
                {
                    if (vehicleType == "Car")
                    {
                        car.Drive(value);
                    }

                    if (vehicleType == "Truck")
                    {
                        truck.Drive(value);
                    }
                }

                else if (command == "Refuel")
                {
                    if (vehicleType == "Car")
                    {
                        car.Refuel(value);
                    }

                    if (vehicleType == "Truck")
                    {
                        truck.Refuel(value);
                    }
                }
            }

            Console.WriteLine($"Car: {car.FuelQuantity:F2}");
            Console.WriteLine($"Truck: {truck.FuelQuantity:F2}");
        }
        public void Run()
        {
            string[] carInfo = Console.ReadLine()
                               .Split(" ", StringSplitOptions.RemoveEmptyEntries);

            string[] truckInfo = Console.ReadLine()
                                 .Split(" ", StringSplitOptions.RemoveEmptyEntries);

            double carFuelQuantity    = double.Parse(carInfo[1]);
            double carFuelCOnsumption = double.Parse(carInfo[2]);

            double truckFuelQuantity    = double.Parse(truckInfo[1]);
            double truckFuelConsumption = double.Parse(truckInfo[2]);

            IVehicle car   = new Car(carFuelQuantity, carFuelCOnsumption);
            IVehicle truck = new Truck(truckFuelQuantity, truckFuelConsumption);

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

            for (int i = 0; i < commandsNumber; i++)
            {
                try
                {
                    string[] input = Console.ReadLine()
                                     .Split(" ", StringSplitOptions.RemoveEmptyEntries);

                    string action      = input[0];
                    string vehicleType = input[1];
                    double value       = double.Parse(input[2]);

                    if (action == "Refuel")
                    {
                        if (vehicleType == "Car")
                        {
                            car.Refuel(value);
                        }
                        else
                        {
                            truck.Refuel(value);
                        }
                    }
                    else
                    {
                        if (vehicleType == "Car")
                        {
                            car.Drive(value);
                        }
                        else
                        {
                            truck.Drive(value);
                        }
                    }
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            Console.WriteLine(car);
            Console.WriteLine(truck);
        }
예제 #6
0
파일: Engine.cs 프로젝트: tolip05/VehicleC-
        public void Run()
        {
            string[] carInfo   = Console.ReadLine().Split();
            string[] truckInfo = Console.ReadLine().Split();
            string[] busInfo   = Console.ReadLine().Split();

            double carFuelQuantiry    = double.Parse(carInfo[1]);
            double carFuelConsumption = double.Parse(carInfo[2]);
            double carTankCapacity    = double.Parse(carInfo[3]);


            double truckFuelQuantiry    = double.Parse(truckInfo[1]);
            double truckFuelConsumption = double.Parse(truckInfo[2]);
            double truckTankCapacity    = double.Parse(truckInfo[3]);

            double   busFuelQuantiry    = double.Parse(busInfo[1]);
            double   busFuelConsumption = double.Parse(busInfo[2]);
            double   busTankCapacity    = double.Parse(busInfo[3]);
            IVehicle car = new Car(carFuelQuantiry, carFuelConsumption, carTankCapacity);

            IVehicle truck = new Truck(truckFuelQuantiry, truckFuelConsumption, truckTankCapacity);

            IVehicle bus = new Bus(busFuelQuantiry, busFuelConsumption, busTankCapacity);

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

            for (int i = 0; i < count; i++)
            {
                try
                {
                    string[] inputArgs   = Console.ReadLine().Split();
                    string   action      = inputArgs[0];
                    string   vehicleType = inputArgs[1];
                    double   valeu       = double.Parse(inputArgs[2]);

                    if (action == "Refuel")
                    {
                        if (vehicleType == "Car")
                        {
                            car.Refuel(valeu);
                        }
                        else if (vehicleType == "Truck")
                        {
                            truck.Refuel(valeu);
                        }
                        else if (vehicleType == "Bus")
                        {
                            bus.Refuel(valeu);
                        }
                    }
                    else if (action == "Drive")
                    {
                        if (vehicleType == "Car")
                        {
                            car.Drive(valeu);
                        }
                        else if (vehicleType == "Truck")
                        {
                            truck.Drive(valeu);
                        }
                        else if (vehicleType == "Bus")
                        {
                            bus.IsVehicleEmpty = false;
                            bus.Drive(valeu);
                        }
                    }
                    else if (action == "DriveEmpty")
                    {
                        bus.IsVehicleEmpty = true;
                        bus.Drive(valeu);
                    }
                }
                catch (ArgumentException e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            Console.WriteLine(car);
            Console.WriteLine(truck);
            Console.WriteLine(bus);
        }
        public void Run()
        {
            var carInput   = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);
            var truckInput = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);
            var busInput   = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);

            double carFuel            = double.Parse(carInput[1]);
            double carFuelConsumption = double.Parse(carInput[2]);
            double carTankCapacity    = double.Parse(carInput[3]);
            Car    car = new Car(carFuel, carFuelConsumption, carTankCapacity);

            double truckFuel            = double.Parse(truckInput[1]);
            double truckFuelConsumption = double.Parse(truckInput[2]);
            double truckTankCapacity    = double.Parse(truckInput[3]);
            Truck  truck = new Truck(truckFuel, truckFuelConsumption, truckTankCapacity);

            double busFuel            = double.Parse(busInput[1]);
            double busFuelConsumption = double.Parse(busInput[2]);
            double busTankCapacity    = double.Parse(busInput[3]);
            Bus    bus = new Bus(busFuel, busFuelConsumption, busTankCapacity);

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

            for (int i = 0; i < lines; i++)
            {
                var currentLine = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);

                string command = currentLine[0];

                string vehicle = currentLine[1];
                try
                {
                    if (command == "Drive")
                    {
                        if (vehicle == "Car")
                        {
                            car.Drive(double.Parse(currentLine[2]));
                        }
                        else if (vehicle == "Truck")
                        {
                            truck.Drive(double.Parse(currentLine[2]));
                        }
                        else if (vehicle == "Bus")
                        {
                            bus.Drive(double.Parse(currentLine[2]));
                        }
                    }
                    else if (command == "Refuel")
                    {
                        if (vehicle == "Car")
                        {
                            car.Refuel(double.Parse(currentLine[2]));
                        }
                        else if (vehicle == "Truck")
                        {
                            truck.Refuel(double.Parse(currentLine[2]));
                        }
                        else if (vehicle == "Bus")
                        {
                            bus.Refuel(double.Parse(currentLine[2]));
                        }
                    }
                    else
                    {
                        bus.DriveEmpty(double.Parse(currentLine[2]));
                    }
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine(ae.Message);
                }
            }

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