Esempio n. 1
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. 2
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. 3
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. 4
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. 5
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. 6
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;
            }
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            string[] carInfo = Console.ReadLine()
                               .Split(" ");
            string[] truckInfo = Console.ReadLine()
                                 .Split(" ");

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

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

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

                switch (commandElements[0])
                {
                case "Drive":
                    double distance = double.Parse(commandElements[2]);

                    switch (commandElements[1])
                    {
                    case "Car":
                        if (car.CanDrive(distance))
                        {
                            car.FuelQuantity -= distance * car.FuelConsumption;
                            Console.WriteLine($"Car travelled {distance} km");
                        }
                        else
                        {
                            Console.WriteLine("Car needs refueling");
                        }
                        break;

                    case "Truck":
                        if (truck.CanDrive(distance))
                        {
                            truck.FuelQuantity -= distance * truck.FuelConsumption;
                            Console.WriteLine($"Truck travelled {distance} km");
                        }
                        else
                        {
                            Console.WriteLine("Truck needs refueling");
                        }
                        break;
                    }
                    break;

                case "Refuel":
                    double fuelLiters = double.Parse(commandElements[2]);

                    switch (commandElements[1])
                    {
                    case "Car":
                        car.Refuel(fuelLiters);
                        break;

                    case "Truck":
                        truck.Refuel(fuelLiters);
                        break;
                    }
                    break;
                }
            }

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