private static void IterateInput(Car car, Truck truck, Bus bus)
        {
            int counter = int.Parse(Console.ReadLine());

            for (int i = 0; i < counter; i++)
            {
                string[] driveInput = ReadInputString();

                string action  = driveInput[0];
                string vehicle = driveInput[1];

                if (action == "Drive")
                {
                    double distance = double.Parse(driveInput[2]);

                    if (vehicle == "Car")
                    {
                        car.Drive(distance);
                    }

                    else if (vehicle == "Truck")
                    {
                        truck.Drive(distance);
                    }

                    else if (vehicle == "Bus")
                    {
                        bus.Drive(distance);
                    }
                }

                else if (action == "Refuel")
                {
                    double liters = double.Parse(driveInput[2]);

                    if (vehicle == "Car")
                    {
                        car.Refuel(liters);
                    }

                    else if (vehicle == "Truck")
                    {
                        truck.Refuel(liters);
                    }

                    else if (vehicle == "Bus")
                    {
                        bus.Refuel(liters);
                    }
                }

                else if (action == "DriveEmpty" && vehicle == "Bus")
                {
                    double distance = double.Parse(driveInput[2]);

                    bus.DriveEmptyBus(distance);
                }
            }
        }
        public void Run()
        {
            var carInfo   = Console.ReadLine().Split();
            var truckInfo = Console.ReadLine().Split();

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

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


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

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

            for (int i = 0; i < actionsCount; i++)
            {
                try
                {
                    var data        = Console.ReadLine().Split();
                    var action      = data[0];
                    var vehicleType = data[1];
                    var value       = double.Parse(data[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 ae)
                {
                    Console.WriteLine(ae.Message);
                }
            }

            Console.WriteLine(car);
            Console.WriteLine(truck);
        }
Beispiel #3
0
        public void Run()
        {
            string[] carInfo   = Console.ReadLine().Split();
            string[] truckInfo = Console.ReadLine().Split();

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

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

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

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

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

                    string action      = inputArgs[0];
                    string vehicleType = inputArgs[1];
                    double value       = double.Parse(inputArgs[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);
        }
        public void Run()
        {
            string[] carInfo   = Console.ReadLine().Split();
            string[] truckInfo = Console.ReadLine().Split();

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

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

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

            Vehicle car   = new Car(carFuelQuantity, carFuelConsumtion);
            Vehicle truck = new Truck(truckFuelQuantity, truckFuelConsumtion);

            for (int i = 0; i < numberOfCommands; i++)
            {
                try
                {
                    string[] commandInput = Console.ReadLine().Split();
                    string   command      = commandInput[0];
                    string   vehicle      = commandInput[1];
                    double   value        = double.Parse(commandInput[2]);

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

            Console.WriteLine(car);
            Console.WriteLine(truck);
        }
Beispiel #5
0
        public void Run()
        {
            var carArgs   = Console.ReadLine().Split();
            var truckArgs = Console.ReadLine().Split();

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

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

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

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

            for (int i = 0; i < n; i++)
            {
                var command = Console.ReadLine().Split();

                var action  = command[0];
                var vehicle = command[1];


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

                    if (vehicle == "Car")
                    {
                        Console.WriteLine(car.Drive(distance));
                    }
                    else if (vehicle == "Truck")
                    {
                        Console.WriteLine(truck.Drive(distance));
                    }
                }
                else if (action == "Refuel")
                {
                    var fuelQuantity = double.Parse(command[2]);
                    if (vehicle == "Car")
                    {
                        car.Refuel(fuelQuantity);
                    }
                    else if (vehicle == "Truck")
                    {
                        truck.Refuel(fuelQuantity);
                    }
                }
            }
            Console.WriteLine(car);
            Console.WriteLine(truck);
        }
        public void Run()
        {
            string[] CarArgs = reader.ReadLine()
                               .Split(' ', StringSplitOptions.RemoveEmptyEntries)
                               .ToArray();

            Car car = new Car(double.Parse(CarArgs[1]), double.Parse(CarArgs[2]));

            string[] TruckArgs = reader.ReadLine()
                                 .Split(' ', StringSplitOptions.RemoveEmptyEntries)
                                 .ToArray();

            Truck truck = new Truck(double.Parse(TruckArgs[1]), double.Parse(TruckArgs[2]));

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

            for (int i = 0; i < n; i++)
            {
                string[] CmdArgs = reader.ReadLine()
                                   .Split(' ', StringSplitOptions.RemoveEmptyEntries)
                                   .ToArray();

                string result = null;
                if (CmdArgs[0] == "Drive")
                {
                    if (CmdArgs[1] == "Car")
                    {
                        result = car.Drive(double.Parse(CmdArgs[2]));
                    }
                    else if (CmdArgs[1] == "Truck")
                    {
                        result = truck.Drive(double.Parse(CmdArgs[2]));
                    }
                    writer.WriteLine(result);
                }
                else if (CmdArgs[0] == "Refuel")
                {
                    if (CmdArgs[1] == "Car")
                    {
                        car.Refuel(double.Parse(CmdArgs[2]));
                    }
                    else if (CmdArgs[1] == "Truck")
                    {
                        truck.Refuel(double.Parse(CmdArgs[2]));
                    }
                }
            }
            writer.WriteLine(car.ToString());
            writer.WriteLine(truck.ToString());
        }
Beispiel #7
0
        public void Run()
        {
            string[] carInfo   = Console.ReadLine().Split();
            string[] truckInfo = Console.ReadLine().Split();

            double carFuel        = double.Parse(carInfo[1]);
            double carConsumption = double.Parse(carInfo[2]);

            ICar car = new Car(carFuel, carConsumption);

            double truckFuel        = double.Parse(truckInfo[1]);
            double truckConsumption = double.Parse(truckInfo[2]);

            ITruck truck = new Truck(truckFuel, truckConsumption);

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

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

                if (input[0] == "Drive")
                {
                    if (input[1] == "Car")
                    {
                        car.Drive(double.Parse(input[2]));
                    }
                    else
                    {
                        truck.Drive(double.Parse(input[2]));
                    }
                }
                else
                {
                    if (input[1] == "Car")
                    {
                        car.Refueled(double.Parse(input[2]));
                    }
                    else
                    {
                        truck.Refueled(double.Parse(input[2]));
                    }
                }
            }

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

            Vehicle car   = new Car(double.Parse(carInfo[1]), double.Parse(carInfo[2]));
            Vehicle truck = new Truck(double.Parse(truckInfo[1]), double.Parse(truckInfo[2]));

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

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

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

            Console.WriteLine(car);
            Console.WriteLine(truck);
        }
Beispiel #9
0
 private static void DriveOrRefuelVehicles(Car car, Truck truck, Bus bus, string[] command, double parsed)
 {
     if (command[0] == "Drive")
     {
         if (command[1] == "Car")
         {
             car.Drive(parsed);
         }
         else if (command[1] == "Truck")
         {
             truck.Drive(parsed);
         }
         else if (command[1] == "Bus")
         {
             bus.Drive(parsed);
         }
     }
     else if (command[0] == "Refuel")
     {
         if (command[1] == "Car")
         {
             car.Refuel(parsed);
         }
         else if (command[1] == "Truck")
         {
             truck.Refuel(parsed);
         }
         else if (command[1] == "Bus")
         {
             bus.Refuel(parsed);
         }
     }
     else if (command[0] == "DriveEmpty")
     {
         if (command[1] == "Bus")
         {
             bus.HasPeople = false;
             bus.Drive(parsed);
         }
     }
 }
        public void Run()
        {
            Car   car            = CarFactory(Console.ReadLine());
            Truck truck          = TruckFactory(Console.ReadLine());
            int   numberCommands = int.Parse(Console.ReadLine());

            for (int i = 0; i < numberCommands; i++)
            {
                string[] lineCommands = Console.ReadLine().Split();
                string   command      = lineCommands[0];
                string   commandType  = lineCommands[1];
                if (command == "Drive")
                {
                    double distance = double.Parse(lineCommands[2]);
                    if (commandType == "Car")
                    {
                        Console.WriteLine(car.Drive(distance));
                    }
                    else
                    {
                        Console.WriteLine(truck.Drive(distance));
                    }
                }
                else if (command == "Refuel")
                {
                    double addQuantity = double.Parse(lineCommands[2]);
                    if (commandType == "Car")
                    {
                        car.Refuel(addQuantity);
                    }
                    else
                    {
                        truck.Refuel(addQuantity);
                    }
                }
            }
            Console.WriteLine(car);
            Console.WriteLine(truck);
        }
        public void Run()
        {
            string[] carArgs = Console.ReadLine().Split();

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

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

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

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

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

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

            double busFuelQuantity    = double.Parse(busArgs[1]);
            double busFuelConsumption = double.Parse(busArgs[2]);
            double busTankQuantity    = double.Parse(busArgs[3]);

            Vehicle bus = new Bus(busFuelQuantity, busFuelConsumption, busTankQuantity);

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

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

                    string action = actionArgs[0];
                    string type   = actionArgs[1];
                    double value  = double.Parse(actionArgs[2]);

                    if (action == "Drive")
                    {
                        if (type == "Car")
                        {
                            car.Drive(value);
                        }
                        else if (type == "Truck")
                        {
                            truck.Drive(value);
                        }
                        else
                        {
                            bus.Drive(value);
                        }
                    }
                    else if (action == "Refuel")
                    {
                        if (type == "Car")
                        {
                            car.Refuel(value);
                        }
                        else if (type == "Truck")
                        {
                            truck.Refuel(value);
                        }
                        else
                        {
                            bus.Refuel(value);
                        }
                    }
                    else
                    {
                        bus.IsEmpty = true;
                        bus.Drive(value);
                    }
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            Console.WriteLine(car);
            Console.WriteLine(truck);
            Console.WriteLine(bus);
        }
Beispiel #12
0
        public void Run()
        {
            string[] carArgs         = Console.ReadLine().Split();
            double   carFuel         = double.Parse(carArgs[1]);
            double   carFuelCons     = double.Parse(carArgs[2]);
            double   carTankCapacity = double.Parse(carArgs[3]);



            string[] truckArgs         = Console.ReadLine().Split();
            double   truckFuel         = double.Parse(truckArgs[1]);
            double   truckFuelCons     = double.Parse(truckArgs[2]);
            double   truckTankCapacity = double.Parse(truckArgs[3]);

            string[] busArgs         = Console.ReadLine().Split();
            double   busFuel         = double.Parse(busArgs[1]);
            double   busFuelCons     = double.Parse(busArgs[2]);
            double   busTankCapacity = double.Parse(busArgs[3]);



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

            try
            {
                Vehicle car = new Car(carFuel, carFuelCons, carTankCapacity);

                Vehicle truck = new Truck(truckFuel, truckFuelCons, truckTankCapacity);

                Vehicle bus = new Bus(busFuel, busFuelCons, busTankCapacity);

                for (int i = 0; i < n; i++)
                {
                    string[] commandArgs = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
                    string   command     = commandArgs[0];
                    string   vehicleType = commandArgs[1];

                    if (command == "Drive")
                    {
                        double distance = double.Parse(commandArgs[2]);
                        if (vehicleType == "Car")
                        {
                            car.Drive(distance);
                        }
                        else if (vehicleType == "Truck")
                        {
                            truck.Drive(distance);
                        }
                        else if (vehicleType == "Bus")
                        {
                            bus.Drive(distance);
                        }
                        else
                        {
                            throw new InvalidOperationException(Messages.InvalidVehicleType);
                        }
                    }
                    else if (command == "Refuel")
                    {
                        double amount = double.Parse(commandArgs[2]);
                        if (vehicleType == "Car")
                        {
                            car.Refuel(amount);
                        }
                        else if (vehicleType == "Truck")
                        {
                            truck.Refuel(amount);
                        }
                        else if (vehicleType == "Bus")
                        {
                            bus.Refuel(amount);
                        }
                        else
                        {
                            throw new InvalidOperationException(Messages.InvalidVehicleType);
                        }
                    }
                    else if (command == "DriveEmpty")
                    {
                        double distance = double.Parse(commandArgs[2]);

                        (bus as Bus).DriveEmpty(distance);
                    }
                    else
                    {
                        throw new InvalidOperationException(Messages.InvalidCommand);
                    }
                }

                Console.WriteLine(car);
                Console.WriteLine(truck);
                Console.WriteLine(bus);
            }
            catch (InvalidOperationException a)
            {
                Console.WriteLine(a.Message);
            }
        }
Beispiel #13
0
        public void Run()
        {
            string[] carInfo = Console.ReadLine().Split();

            fuelQtty    = double.Parse(carInfo[1]);
            consumption = double.Parse(carInfo[2]);

            IVehicle car = new Car(fuelQtty, consumption);

            car.AirConditionOn();

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

            fuelQtty    = double.Parse(truckInfo[1]);
            consumption = double.Parse(truckInfo[2]);

            IVehicle truck = new Truck(fuelQtty, consumption);

            truck.AirConditionOn();

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

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

                string comandType  = commandArgs[0];
                string vehicleType = commandArgs[1];

                try
                {
                    switch (comandType)
                    {
                    case "Drive":
                        double distanceToCover = double.Parse(commandArgs[2]);

                        switch (vehicleType)
                        {
                        case "Car":
                            car.Drive(distanceToCover);
                            Console.WriteLine(car);
                            break;

                        case "Truck":
                            truck.Drive(distanceToCover);
                            Console.WriteLine(truck);
                            break;
                        }
                        break;

                    case "Refuel":
                        double fuelAmount = double.Parse(commandArgs[2]);

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

                        case "Truck":
                            truck.Refuel(fuelAmount);
                            break;
                        }
                        break;
                    }
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            Console.WriteLine($"Car: {car.FuelQtty:f2}");
            Console.WriteLine($"Truck: {truck.FuelQtty:f2}");
        }
        public void Run()
        {
            string[] carInfo = this.reader.ReadLine().Split().ToArray();
            ICar     car     = new Car(double.Parse(carInfo[1]), double.Parse(carInfo[2]), int.Parse(carInfo[3]));

            vehicles.Add(car);


            string[] truckInfo = this.reader.ReadLine().Split().ToArray();
            ITruck   truck     = new Truck(double.Parse(truckInfo[1]), double.Parse(truckInfo[2]), int.Parse(truckInfo[3]));

            vehicles.Add(truck);


            string[] busInfo = this.reader.ReadLine().Split().ToArray();
            IBus     bus     = new Bus(double.Parse(busInfo[1]), double.Parse(busInfo[2]), int.Parse(busInfo[3]));

            vehicles.Add(bus);


            int commandCount = int.Parse(this.reader.ReadLine());



            for (int i = 0; i < commandCount; i++)
            {
                string command = this.reader.ReadLine();

                string[] commandSplit = command.Split().ToArray();

                string actionType  = commandSplit[0];
                string vehicleType = commandSplit[1];
                double amount      = double.Parse(commandSplit[2]);

                if (actionType == "Drive")
                {
                    if (vehicleType == "Car")
                    {
                        this.writer.WriteLine(car.Drive(amount));
                    }
                    else if (vehicleType == "Truck")
                    {
                        this.writer.WriteLine(truck.Drive(amount));
                    }
                    else
                    {
                        this.writer.WriteLine(bus.Drive(amount));
                    }
                }
                else if (actionType == "Refuel")
                {
                    try
                    {
                        if (vehicleType == "Car")
                        {
                            car.Refuel(amount);
                        }
                        else if (vehicleType == "Truck")
                        {
                            truck.Refuel(amount);
                        }
                        else
                        {
                            bus.Refuel(amount);
                        }
                    }
                    catch (ArgumentException ae)
                    {
                        this.writer.WriteLine(ae.Message);
                    }
                }
                else
                {
                    this.writer.WriteLine(bus.DriveEmpty(amount));
                }
            }


            foreach (IVehicle vehicle in vehicles)
            {
                this.writer.WriteLine(vehicle.ToString());
            }
        }
Beispiel #15
0
        public void Run()
        {
            string[] carInfo = Console.ReadLine()
                               .Split()
                               .ToArray();

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

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

            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]);

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


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

            for (int i = 0; i < n; i++)
            {
                try
                {
                    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);
                        }

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

                        else if (vehicleType == "Bus")
                        {
                            bus.Drive(value);
                        }
                    }

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

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

                        else if (vehicleType == "Bus")
                        {
                            bus.Refuel(value);
                        }
                    }

                    else if (command == "DriveEmpty")
                    {
                        bus.isEmpty = true;
                        bus.Drive(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}");
        }
        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());
        }
Beispiel #17
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);
        }
Beispiel #18
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}");
        }
Beispiel #19
0
        public void Run()
        {
            string[] carInfo = Console.ReadLine()
                               .Split(' ', StringSplitOptions.RemoveEmptyEntries);
            string[] truckInfo = Console.ReadLine()
                                 .Split(' ', StringSplitOptions.RemoveEmptyEntries);
            string[] busInfo = Console.ReadLine()
                               .Split(' ', StringSplitOptions.RemoveEmptyEntries);


            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++)
            {
                try
                {
                    string[] commandArgs = Console.ReadLine()
                                           .Split(' ', StringSplitOptions.RemoveEmptyEntries);
                    string action      = commandArgs[0];
                    string vehicleType = commandArgs[1];
                    double value       = double.Parse(commandArgs[2]);

                    if (action == "Refuel")
                    {
                        if (vehicleType == "Car")
                        {
                            car.Refuel(value);
                        }
                        else if (vehicleType == "Truck")
                        {
                            truck.Refuel(value);
                        }
                        else if (vehicleType == "Bus")
                        {
                            bus.Refuel(value);
                        }
                    }
                    else if (action == "Drive")
                    {
                        if (vehicleType == "Car")
                        {
                            car.Drive(value);
                        }
                        else if (vehicleType == "Truck")
                        {
                            truck.Drive(value);
                        }
                        else if (vehicleType == "Bus")
                        {
                            bus.IsVehicleEmpty = false;
                            bus.Drive(value);
                        }
                    }
                    else if (action == "DriveEmpty")
                    {
                        bus.IsVehicleEmpty = true;
                        bus.Drive(value);
                    }
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            Console.WriteLine(car);
            Console.WriteLine(truck);
            Console.WriteLine(bus);
        }
        public void Run()
        {
            string[] carArgs = Console.ReadLine().Split();

            double fuel         = double.Parse(carArgs[1]);
            double littersPerKm = double.Parse(carArgs[2]);
            double tank         = double.Parse(carArgs[3]);

            IVehicle car = new Car(fuel, littersPerKm, tank);

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

            fuel         = double.Parse(truckArgs[1]);
            littersPerKm = double.Parse(truckArgs[2]);
            tank         = double.Parse(truckArgs[3]);

            IVehicle truck = new Truck(fuel, littersPerKm, tank);

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

            fuel         = double.Parse(busArgs[1]);
            littersPerKm = double.Parse(busArgs[2]);
            tank         = double.Parse(busArgs[3]);

            IVehicle bus = new Bus(fuel, littersPerKm, tank);

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

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

                string command = inputArgs[0];
                string type    = inputArgs[1];

                if (type == "Car")
                {
                    if (command == "Drive")
                    {
                        double distance = double.Parse(inputArgs[2]);
                        car.Drive(distance);
                    }
                    else if (command == "Refuel")
                    {
                        double litters = double.Parse(inputArgs[2]);
                        car.Refuel(litters);
                    }
                }
                else if (type == "Truck")
                {
                    if (command == "Drive")
                    {
                        double distance = double.Parse(inputArgs[2]);
                        truck.Drive(distance);
                    }
                    else if (command == "Refuel")
                    {
                        double litters = double.Parse(inputArgs[2]);
                        truck.Refuel(litters);
                    }
                }
                else if (type == "Bus")
                {
                    if (command == "DriveEmpty")
                    {
                        bus.IsVehicleEmpty = true;
                        double distance = double.Parse(inputArgs[2]);
                        bus.Drive(distance);
                    }
                    else if (command == "Drive")
                    {
                        bus.IsVehicleEmpty = false;
                        double distance = double.Parse(inputArgs[2]);
                        bus.Drive(distance);
                    }
                    else if (command == "Refuel")
                    {
                        double litters = double.Parse(inputArgs[2]);
                        bus.Refuel(litters);
                    }
                }
            }

            Console.WriteLine($"Car: {car.FuelQuantity:f2}");
            Console.WriteLine($"Truck: {truck.FuelQuantity:f2}");
            Console.WriteLine($"Bus: {bus.FuelQuantity:f2}");
        }
Beispiel #21
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]);
            IVehicle car = new Car(carFuelQuantity, carFuelConsumption, carTankCapacity);

            double   truckFuelQuantity    = double.Parse(truckInfo[1]);
            double   truckFuelConsumption = double.Parse(truckInfo[2]);
            double   truckTankCapacity    = double.Parse(truckInfo[3]);
            IVehicle truck = new Truck(truckFuelQuantity, truckFuelConsumption, truckTankCapacity);

            double   busFuelQuantity    = double.Parse(busInfo[1]);
            double   busFuelConsumption = double.Parse(busInfo[2]);
            double   busTankCapacity    = double.Parse(busInfo[3]);
            IVehicle bus = new Bus(busFuelQuantity, busFuelConsumption, busTankCapacity);

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

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

                try
                {
                    if (vehicleType == "Car")
                    {
                        if (command == "Drive")
                        {
                            car.Drive(value);
                        }
                        else if (command == "Refuel")
                        {
                            car.Refuel(value);
                        }
                    }
                    else if (vehicleType == "Truck")
                    {
                        if (command == "Drive")
                        {
                            truck.Drive(value);
                        }
                        else if (command == "Refuel")
                        {
                            truck.Refuel(value);
                        }
                    }
                    else if (vehicleType == "Bus")
                    {
                        if (command == "Drive")
                        {
                            bus.VehicleIsEmpty = false;
                            bus.Drive(value);
                        }
                        else if (command == "DriveEmpty")
                        {
                            bus.VehicleIsEmpty = true;
                            bus.Drive(value);
                        }
                        else if (command == "Refuel")
                        {
                            bus.Refuel(value);
                        }
                    }
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            Console.WriteLine(car);
            Console.WriteLine(truck);
            Console.WriteLine(bus);
        }
Beispiel #22
0
        public void Run()
        {
            var carArgs   = Console.ReadLine().Split();
            var truckArgs = Console.ReadLine().Split();
            var busArgs   = Console.ReadLine().Split();

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

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

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

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



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

            for (int i = 0; i < n; i++)
            {
                var command = Console.ReadLine().Split();

                var action  = command[0];
                var vehicle = command[1];

                try
                {
                    if (action == "Drive")
                    {
                        var distance = double.Parse(command[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.Drive(distance));
                        }
                    }
                    else if (action == "Refuel")
                    {
                        var fuelQuantity = double.Parse(command[2]);
                        if (vehicle == "Car")
                        {
                            car.Refuel(fuelQuantity);
                        }
                        else if (vehicle == "Truck")
                        {
                            truck.Refuel(fuelQuantity);
                        }
                        else if (vehicle == "Bus")
                        {
                            bus.Refuel(fuelQuantity);
                        }
                    }
                    else if (action == "DriveEmpty")
                    {
                        var kilometers = double.Parse(command[2]);
                        var busAs      = bus as Bus;

                        Console.WriteLine(busAs.DriveEmpty(kilometers));
                    }
                }
                catch (ArgumentException msg)
                {
                    Console.WriteLine(msg.Message);
                }
            }
            Console.WriteLine(car);
            Console.WriteLine(truck);
            Console.WriteLine(bus);
        }
Beispiel #23
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);
        }
        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);
        }