private static void Execution(Car car, Truck truck, Bus bus, int n)
        {
            for (int i = 0; i < n; i++)
            {
                string[] commands    = Console.ReadLine().Split();
                string   command     = commands[0];
                string   typeVehicle = commands[1];

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

                    if (typeVehicle == "Car")
                    {
                        Console.WriteLine(car.Drive(distance));
                    }
                    else if (typeVehicle == "Truck")
                    {
                        Console.WriteLine(truck.Drive(distance));
                    }
                    else
                    {
                        Console.WriteLine(bus.Drive(distance));
                    }
                }
                else if (command == "Refuel")
                {
                    try
                    {
                        double refuelQuantity = double.Parse(commands[2]);

                        if (typeVehicle == "Car")
                        {
                            car.Refuel(refuelQuantity);
                        }
                        else if (typeVehicle == "Truck")
                        {
                            truck.Refuel(refuelQuantity);
                        }
                        else
                        {
                            bus.Refuel(refuelQuantity);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                else
                {
                    double distance = double.Parse(commands[2]);
                    Console.WriteLine(bus.DriveEmpty(distance));
                }
            }
        }
Esempio n. 2
0
        static void Main()
        {
            var carInput   = Console.ReadLine().Split();
            var truckInput = Console.ReadLine().Split();
            var busInput   = Console.ReadLine().Split();

            Vehicle car              = new Car(double.Parse(carInput[1]), double.Parse(carInput[2]), double.Parse(carInput[3]));
            Vehicle truck            = new Truck(double.Parse(truckInput[1]), double.Parse(truckInput[2]), double.Parse(truckInput[3]));
            Bus     bus              = new Bus(double.Parse(busInput[1]), double.Parse(busInput[2]), double.Parse(busInput[3]));
            int     numberOfCommands = int.Parse(Console.ReadLine());

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

                if (command[0].StartsWith('D'))
                {
                    if (command[0] == "DriveEmpty")
                    {
                        bus.DriveEmpty(double.Parse(command[2]));
                    }
                    else
                    {
                        if (command[1].StartsWith('C'))
                        {
                            car.Drive(double.Parse(command[2]));
                        }
                        else if (command[1].StartsWith('T'))
                        {
                            truck.Drive(double.Parse(command[2]));
                        }
                        else if (command[1].StartsWith('B'))
                        {
                            bus.Drive(double.Parse(command[2]));
                        }
                    }
                }
                else if (command[0].StartsWith('R'))
                {
                    if (command[1].StartsWith('C'))
                    {
                        car.Refuel(double.Parse(command[2]));
                    }
                    else if (command[1].StartsWith('T'))
                    {
                        truck.Refuel(double.Parse(command[2]));
                    }
                    else if (command[1].StartsWith('B'))
                    {
                        bus.Refuel(double.Parse(command[2]));
                    }
                }
            }

            Console.WriteLine($"Car: {car.fuelQuantity:f2}\nTruck: {truck.fuelQuantity:f2}\nBus: {bus.fuelQuantity:f2}");
        }
Esempio n. 3
0
 private static void ExecuteRefuelCommand(string[] command, Car car, Truck truck, Bus bus)
 {
     if (command[1] == "Car")
     {
         car.Refuel(double.Parse(command[2]));
     }
     else if (command[1] == "Truck")
     {
         truck.Refuel(double.Parse(command[2]));
     }
     else if (command[1] == "Bus")
     {
         bus.Refuel(double.Parse(command[2]));
     }
 }
Esempio n. 4
0
        private static void ApplyChanges(Vehicle car, Vehicle truck, Bus bus, string cmdType, string whatToGet, double distance)
        {
            if (cmdType == "Drive")
            {
                if (whatToGet == "Car")
                {
                    Console.WriteLine(car.Drive(distance));
                }
                else if (whatToGet == "Truck")
                {
                    Console.WriteLine(truck.Drive(distance));
                }
                else if (whatToGet == "Bus")
                {
                    Console.WriteLine(bus.Drive(distance));
                }
            }
            else if (cmdType == "Refuel")
            {
                var amount = distance;

                if (whatToGet == "Car")
                {
                    car.Refuel(amount);
                }
                else if (whatToGet == "Truck")
                {
                    truck.Refuel(amount);
                }
                else if (whatToGet == "Bus")
                {
                    bus.Refuel(amount);
                }
            }
            else if (cmdType == "DriveEmpty")
            {
                Console.WriteLine(bus.DriveEmpty(distance));
            }
        }
Esempio n. 5
0
        public static void Main()
        {
            try
            {
                var carInfo   = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                var truckInfo = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                var busInfo   = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                var car   = new Car(double.Parse(carInfo[1]), double.Parse(carInfo[2]), double.Parse(carInfo[3]));
                var truck = new Truck(double.Parse(truckInfo[1]), double.Parse(truckInfo[2]), double.Parse(truckInfo[3]));
                var bus   = new Bus(double.Parse(busInfo[1]), double.Parse(busInfo[2]), double.Parse(busInfo[3]));

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

                for (int i = 0; i < N; i++)
                {
                    var command = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                    switch (command[0])
                    {
                    case "Drive":
                        var distance = double.Parse(command[2]);
                        switch (command[1])
                        {
                        case "Car":
                            car.Drive(distance);
                            break;

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

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

                    case "Refuel":
                        var litersToRefuel = double.Parse(command[2]);
                        switch (command[1])
                        {
                        case "Car":
                            car.Refuel(litersToRefuel);
                            break;

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

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

                    case "DriveEmpty":
                        distance             = double.Parse(command[2]);
                        bus.FuelConsumption -= 1.4;
                        bus.Drive(distance);
                        break;
                    }
                }

                Console.WriteLine("Car: {0:F2}", car.FuelQuantity);
                Console.WriteLine("Truck: {0:F2}", truck.FuelQuantity);
                Console.WriteLine("Bus: {0:F2}", bus.FuelQuantity);
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            string[] carInput = Console.ReadLine().Split();

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

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

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

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

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

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

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

                if (input[0] == "DriveEmpty")
                {
                    bus.DriveEmpty(double.Parse(input[2]));
                }

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

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

            Console.WriteLine($"Car: {car.FuelQuantity:F2}");
            Console.WriteLine($"Truck: {truck.FuelQuantity:F2}");
            Console.WriteLine($"Bus: {bus.FuelQuantity:F2}");
        }
Esempio n. 7
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. 8
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. 9
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. 10
0
        public static void Main()
        {
            string[] line1 = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            string[] line2 = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            string[] line3 = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            int      n     = int.Parse(Console.ReadLine());

            Car   car   = new Car(double.Parse(line1[1]), (double.Parse(line1[2]) + 0.9), double.Parse(line1[3]));
            Truck truck = new Truck(double.Parse(line2[1]), (double.Parse(line2[2]) + 1.6), double.Parse(line2[3]));
            Bus   bus   = new Bus(double.Parse(line3[1]), (double.Parse(line3[2]) + 1.4), double.Parse(line3[3]));

            for (int i = 0; i < n; i++)
            {
                try
                {
                    string[] input = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                    string command          = input[0];
                    string typeVehicle      = input[1];
                    double distanceOrLiters = double.Parse(input[2]);

                    switch (command)
                    {
                    case "Drive":
                        if (typeVehicle == "Car")
                        {
                            car.Drive(distanceOrLiters);
                        }
                        else if (typeVehicle == "Truck")
                        {
                            truck.Drive(distanceOrLiters);
                        }
                        else if (typeVehicle == "Bus")
                        {
                            bus.Drive(distanceOrLiters);
                        }

                        break;

                    case "Refuel":
                        if (typeVehicle == "Car")
                        {
                            car.Refuel(distanceOrLiters);
                        }
                        else if (typeVehicle == "Truck")
                        {
                            truck.Refuel(distanceOrLiters);
                        }
                        else if (typeVehicle == "Bus")
                        {
                            bus.Refuel(distanceOrLiters);
                        }

                        break;

                    case "DriveEmpty":
                        bus.DriveEmpty(distanceOrLiters);
                        break;

                    default: break;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            Console.WriteLine(car);
            Console.WriteLine(truck);
            Console.WriteLine(bus);
        }
Esempio n. 11
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;
            }
        }