Esempio n. 1
0
        static void doWork()
        {
            Console.WriteLine("This is the vehicles lab.");
            Console.WriteLine("Journey by airplane:");
            Airplane myPlane = new Airplane();

            myPlane.StartEngine("Contact");
            myPlane.TakeOff();
            myPlane.Drive();
            myPlane.Land();
            myPlane.StopEngine("Whirr");
            Console.WriteLine();
            Console.WriteLine("=======================================");
            Console.WriteLine("Journey by car:");
            Car myCar = new Car();

            myCar.StartEngine("Brm brm");
            myCar.Accelerate();
            myCar.Drive();
            myCar.Brake();
            myCar.StopEngine("Phut phut");
            Console.WriteLine("=======================================");
            Console.WriteLine("Journey by truck:");
            Truck steven = new Truck();

            steven.StartEngine("Diesel Clatter");
            steven.Accelerate();
            steven.Drive();
            steven.Brake();
            steven.StopEngine("Clunk Clunk");
            Console.WriteLine("=======================================");
            Console.WriteLine("Journey by boat:");
            Boat titanic = new Boat();

            titanic.StartEngine("Vroom Vroom");
            titanic.Accelerate();
            titanic.Drive();
            titanic.Brake();
            titanic.StopEngine("Glug Glug");
            Console.WriteLine("=======================================");
            Console.WriteLine("\nTesting polymorphism");
            Vehicle v = myCar;

            v.Drive();
            v = myPlane;
            v.Drive();
            v = steven;
            steven.Drive();
            Console.WriteLine("=======================================");
        }
Esempio n. 2
0
        private static void DriveCommand(string[] commandParts)

        {
            string vehicle = commandParts[1];

            switch (vehicle)

            {
            case "Car":

                car.Drive(double.Parse(commandParts[2]));

                break;

            case "Truck":

                truck.Drive(double.Parse(commandParts[2]));

                break;

            case "Bus":

                bus.Drive(double.Parse(commandParts[2]));

                break;
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            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]);

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

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

            for (int i = 0; i < numberOfOperations; i++)
            {
                string[] cmdArgs = Console.ReadLine()
                                   .Split(" ", StringSplitOptions.RemoveEmptyEntries);
                string option = cmdArgs[0];
                string type   = cmdArgs[1];
                double amount = double.Parse(cmdArgs[2]);

                if (option == "Drive")
                {
                    try
                    {
                        if (type == nameof(Car))
                        {
                            car.Drive(amount);
                        }
                        else if (type == nameof(Truck))
                        {
                            truck.Drive(amount);
                        }
                    }
                    catch (ArgumentException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                else if (option == "Refuel")
                {
                    if (type == nameof(Car))
                    {
                        car.Refuel(amount);
                    }
                    else if (type == nameof(Truck))
                    {
                        truck.Refuel(amount);
                    }
                }
            }

            Console.WriteLine($"Car: {car.FuelQuantity:f2}");
            Console.WriteLine($"Truck: {truck.FuelQuantity:f2}");
        }
Esempio n. 4
0
        private static void Main()
        {
            string[] carItems = Console.ReadLine()
                                .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

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

            Car car = new Car(carFuelQuantity, carFuelConsumption);

            string[] truckItems = Console.ReadLine()
                                  .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

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

            Truck truck = new Truck(truckFuelQuantity, truckFuelConsumption);

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

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

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

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

                    if (type == "Car")
                    {
                        Console.WriteLine(car.Drive(distance));
                    }
                    else
                    {
                        Console.WriteLine(truck.Drive(distance));
                    }
                }
                else if (command == "Refuel")
                {
                    double fuel = double.Parse(commandItems[2]);

                    if (type == "Car")
                    {
                        car.Refuel(fuel);
                    }
                    else
                    {
                        truck.Refuel(fuel);
                    }
                }
            }

            Console.WriteLine(car.ToString());
            Console.WriteLine(truck.ToString());
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            string[] carTokens    = Console.ReadLine().Split();
            double   fuelConsum   = double.Parse(carTokens[2]);
            double   fuelQuantity = double.Parse(carTokens[1]);
            Car      car          = new Car(carTokens[1], carTokens[2], carTokens[3]);

            string[] truckTokens = Console.ReadLine().Split();
            Truck    truck       = new Truck(truckTokens[1], truckTokens[2], truckTokens[3]);

            string[] busTokens       = Console.ReadLine().Split();
            Bus      bus             = new Bus(busTokens[1], busTokens[2], busTokens[3]);
            int      numberOfComands = int.Parse(Console.ReadLine());

            for (int i = 0; i < numberOfComands; i++)
            {
                string[] comand = Console.ReadLine().Split();
                if (comand[0] == "Drive")
                {
                    double distance = double.Parse(comand[2]);
                    if (comand[1] == "Car")
                    {
                        car.Drive(distance);
                    }
                    else if (comand[1] == "Truck")
                    {
                        truck.Drive(distance);
                    }
                    else if (comand[1] == "Bus")
                    {
                        bus.DrivewithPassenger(distance);
                    }
                }
                else if (comand[0] == "Refuel")
                {
                    double quantity = double.Parse(comand[2]);
                    if (comand[1] == "Car")
                    {
                        car.Refuel(quantity);
                    }
                    else if (comand[1] == "Truck")
                    {
                        truck.Refuel(quantity);
                    }
                    else if (comand[1] == "Bus")
                    {
                        bus.Refuel(quantity);
                    }
                }
                else if (comand[0] == "DriveEmpty")
                {
                    bus.DrivewithPassenger(double.Parse(comand[2]));
                }
            }
            Console.WriteLine(car);
            Console.WriteLine(truck);
            Console.WriteLine(bus);
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split();
            var      car   = new Car(double.Parse(input[1]), double.Parse(input[2]), double.Parse(input[3]));

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

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

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

            for (int counter = 0; counter < numberOfLines; counter++)
            {
                input = Console.ReadLine().Split();
                double distancesOrQuantity = double.Parse(input[2]);

                if (input[0] == "Drive")
                {
                    if (input[1] == "Car")
                    {
                        car.Drive(distancesOrQuantity);
                    }
                    else if (input[1] == "Truck")
                    {
                        truck.Drive(distancesOrQuantity);
                    }
                    else
                    {
                        bus.Drive(distancesOrQuantity);
                    }
                }
                else if (input[0] == "Refuel")
                {
                    if (input[1] == "Car")
                    {
                        car.Refuel(distancesOrQuantity);
                    }
                    else if (input[1] == "Truck")
                    {
                        truck.Refuel(distancesOrQuantity);
                    }
                    else
                    {
                        truck.Refuel(distancesOrQuantity);
                    }
                }
                else
                {
                    bus.DriveEmptyBus(distancesOrQuantity);
                }
            }

            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[] args)
        {
            string[] tokens = Console.ReadLine().Split();
            Car      car    = new Car(double.Parse(tokens[1]), double.Parse(tokens[2]), double.Parse(tokens[3]));

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

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

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

            for (int i = 0; i < n; i++)
            {
                tokens = Console.ReadLine().Split();
                if (tokens[0] == "Drive")
                {
                    if (tokens[1] == "Car")
                    {
                        Console.WriteLine(car.Drive(double.Parse(tokens[2])));
                    }
                    else if (tokens[1] == "Truck")
                    {
                        Console.WriteLine(truck.Drive(double.Parse(tokens[2])));
                    }
                    else
                    {
                        Console.WriteLine(bus.Drive(double.Parse(tokens[2])));
                    }
                }
                else if (tokens[0] == "Refuel")
                {
                    if (tokens[1] == "Car")
                    {
                        car.Refuel(double.Parse(tokens[2]));
                    }
                    else if (tokens[1] == "Truck")
                    {
                        truck.Refuel(double.Parse(tokens[2]));
                    }
                    else
                    {
                        bus.Refuel(double.Parse(tokens[2]));
                    }
                }
                else // DriveEmpty
                {
                    Console.WriteLine(bus.DriveEmpty(double.Parse(tokens[2])));
                }
            }

            Console.WriteLine($"Car: {car.FuelQuantity:F2}");
            Console.WriteLine($"Truck: {truck.FuelQuantity:F2}");
            Console.WriteLine($"Bus: {bus.FuelQuantity:F2}");
        }
        public void Run()
        {
            Car   car   = CreateCar();
            Truck truck = CreateTruck();

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

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

                    string command      = commandArgs[0];
                    string vechicleType = commandArgs[1];

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

                        if (vechicleType == "Car")
                        {
                            Console.WriteLine(car.Drive(distance));
                        }
                        else if (vechicleType == "Truck")
                        {
                            Console.WriteLine(truck.Drive(distance));
                        }
                        break;

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

                        if (vechicleType == "Car")
                        {
                            car.Refuel(fuelAmount);
                        }
                        else if (vechicleType == "Truck")
                        {
                            truck.Refuel(fuelAmount);
                        }
                        break;
                    }
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine(ae.Message);
                    continue;
                }
            }

            Console.WriteLine(car.ToString());
            Console.WriteLine(truck.ToString());
        }
Esempio n. 9
0
        static void Main(string[] args)
        {
            string[] vechicleData = Console.ReadLine().Split();
            Car      car          = new Car(double.Parse(vechicleData[1]), double.Parse(vechicleData[2]), double.Parse(vechicleData[3]));

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

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

            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] == nameof(Car))
                    {
                        car.Drive(double.Parse(input[2]));
                    }
                    else if (input[1] == nameof(Truck))
                    {
                        truck.Drive(double.Parse(input[2]));
                    }
                    else if (input[1] == nameof(Bus))
                    {
                        bus.Drive(double.Parse(input[2]));
                    }
                }
                else if (input[0] == "Refuel")
                {
                    if (input[1] == nameof(Car))
                    {
                        car.Refuel(double.Parse(input[2]));
                    }
                    else if (input[1] == nameof(Truck))
                    {
                        truck.Refuel(double.Parse(input[2]));
                    }
                    else if (input[1] == nameof(Bus))
                    {
                        bus.Refuel(double.Parse(input[2]));
                    }
                }
                else if (input[0] == "DriveEmpty" && input[1] == nameof(Bus))
                {
                    bus.DriveEmpty(double.Parse(input[2]));
                }
            }

            Console.WriteLine($"Car: {car.FuelQuantity:F2}");
            Console.WriteLine($"Truck: {truck.FuelQuantity:F2}");
            Console.WriteLine($"Bus: {bus.FuelQuantity:F2}");
        }
Esempio n. 10
0
        static void Main(string[] args)
        {
            string[] carArgs   = Console.ReadLine().Split();
            string[] truckArgs = Console.ReadLine().Split();
            Vehicle  car       = new Car(double.Parse(carArgs[1]), double.Parse(carArgs[2]));
            Vehicle  truck     = new Truck(double.Parse(truckArgs[1]), double.Parse(truckArgs[2]));

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

            for (int curr = 0; curr < numberOfCommands; curr++)
            {
                string[] inputArgs  = Console.ReadLine().Split();
                string   command    = inputArgs[0];
                string   vehicle    = inputArgs[1];
                double   commandArg = double.Parse(inputArgs[2]);

                switch (command)
                {
                case "Drive":
                    try
                    {
                        if (vehicle == "Car")
                        {
                            car.Drive(commandArg);
                            Console.WriteLine($"Car travelled {commandArg} km");
                        }
                        else if (vehicle == "Truck")
                        {
                            truck.Drive(commandArg);
                            Console.WriteLine($"Truck travelled {commandArg} km");
                        }
                    }
                    catch (ArgumentException ae)
                    {
                        Console.WriteLine(ae.Message);
                    }
                    break;

                case "Refuel":
                    if (vehicle == "Car")
                    {
                        car.Refuel(commandArg);
                    }
                    else if (vehicle == "Truck")
                    {
                        truck.Refuel(commandArg);
                    }
                    break;

                default: break;
                }
            }
            Console.WriteLine(car);
            Console.WriteLine(truck);
        }
Esempio n. 11
0
        public static void Main()
        {
            // "Car {fuel quantity} {liters per km}"
            string[] carInfoArgs = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
            var      car         = new Car(double.Parse(carInfoArgs[1]), double.Parse(carInfoArgs[2]));

            // "Truck {fuel quantity} {liters per km}"
            string[] truckInfoArgs = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
            var      truck         = new Truck(double.Parse(truckInfoArgs[1]), double.Parse(truckInfoArgs[2]));

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

            for (int i = 0; i < N; i++)
            {
                // read cmds
                string[] cmdArgs = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
                if (cmdArgs[0] == "Drive")
                {
                    try
                    {
                        double distance = double.Parse(cmdArgs[2]);
                        if (cmdArgs[1] == "Car")
                        {
                            car.Drive(distance);
                        }
                        else if (cmdArgs[1] == "Truck")
                        {
                            truck.Drive(distance);
                        }

                        Console.WriteLine($"{cmdArgs[1]} travelled {distance} km");
                    }
                    catch (ArgumentException ex)
                    {
                        Console.WriteLine(ex.Message);;
                    }
                }
                else if (cmdArgs[0] == "Refuel")
                {
                    double liters = double.Parse(cmdArgs[2]);
                    if (cmdArgs[1] == "Car")
                    {
                        car.Refuel(liters);
                    }
                    else if (cmdArgs[1] == "Truck")
                    {
                        truck.Refuel(liters);
                    }
                }
            }

            Console.WriteLine($"Car: {car.FuelQuantity:F2}");
            Console.WriteLine($"Truck: {truck.FuelQuantity:F2}");
        }
Esempio n. 12
0
        static void Main(string[] args)
        {
            var carInfo = Console.ReadLine()
                          .Split(" ", StringSplitOptions.RemoveEmptyEntries);

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

            Car car = new Car(carInfo[0], carFuelQuantity, carFuelConsumption);

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

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

            Truck truck = new Truck(truckInfo[0], truckFuelQuantity, truckFuelConsumption);

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

            for (int i = 0; i < count; i++)
            {
                var infoLine = Console.ReadLine()
                               .Split(" ");
                var command        = infoLine[0];
                var currentVehicle = infoLine[1];
                var fuelOrDistance = double.Parse(infoLine[2]);

                if (command == "Drive")
                {
                    if (currentVehicle == "Car")
                    {
                        car.Drive(fuelOrDistance);
                    }
                    else if (currentVehicle == "Truck")
                    {
                        truck.Drive(fuelOrDistance);
                    }
                }
                else if (command == "Refuel")
                {
                    if (currentVehicle == "Car")
                    {
                        car.Refuel(fuelOrDistance);
                    }
                    else if (currentVehicle == "Truck")
                    {
                        truck.Refuel(fuelOrDistance);
                    }
                }
            }
            Console.WriteLine(car);
            Console.WriteLine(truck);
        }
Esempio n. 13
0
        public void Run()
        {
            string[] carInfo = Console.ReadLine()
                               .Split(" ", StringSplitOptions.RemoveEmptyEntries)
                               .ToArray();
            string[] truckInfo = Console.ReadLine()
                                 .Split(" ", StringSplitOptions.RemoveEmptyEntries)
                                 .ToArray();
            int commandsCount = int.Parse(Console.ReadLine());

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

            for (int i = 0; i < commandsCount; i++)
            {
                string[] command = Console.ReadLine()
                                   .Split(" ", StringSplitOptions.RemoveEmptyEntries)
                                   .ToArray();
                string action      = command[0]?.ToLower();
                string vehicleType = command[1]?.ToLower();
                double quantity    = double.Parse(command[2]);

                switch (action)
                {
                case "drive":
                    if (vehicleType == "car")
                    {
                        car.Drive(quantity);
                    }
                    else if (vehicleType == "truck")
                    {
                        truck.Drive(quantity);
                    }
                    break;

                case "refuel":
                    if (vehicleType == "car")
                    {
                        car.Refuel(quantity);
                    }
                    else if (vehicleType == "truck")
                    {
                        truck.Refuel(quantity);
                    }
                    break;

                default:
                    break;
                }
            }

            Console.WriteLine(car);
            Console.WriteLine(truck);
        }
Esempio n. 14
0
        public static void Main(string[] args)
        {
            string[] firstInput         = Console.ReadLine().Split();
            double   carFuelQuantity    = double.Parse(firstInput[1]);
            double   carFuelConsumption = double.Parse(firstInput[2]);

            string[] secondInput          = Console.ReadLine().Split();
            double   truckFuelQuantity    = double.Parse(secondInput[1]);
            double   truckFuelConsumption = double.Parse(secondInput[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   input    = Console.ReadLine();
                string[] splitted = input.Split();
                string   command  = splitted[0];
                string   vehicle  = splitted[1];



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

            Console.WriteLine($"Car: {car.FuelQuantity:F2}");
            Console.WriteLine($"Truck: {truck.FuelQuantity:F2}");
        }
Esempio n. 15
0
        static void Main(string[] args)
        {
            string[] carInfo   = Console.ReadLine().Split();
            string[] truckInfo = Console.ReadLine().Split();
            string[] busInfo   = Console.ReadLine().Split();
            int      n         = int.Parse(Console.ReadLine());

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

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

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

                double distanceOrLitters = double.Parse(input[2]);

                switch (command)
                {
                case "Drive":
                    Console.WriteLine(vehicle == "Car"
                            ? car.Drive(distanceOrLitters)
                            : truck.Drive(distanceOrLitters));
                    break;

                case "Refuel":
                    switch (vehicle)
                    {
                    case "Car":
                        car.Refuel(distanceOrLitters);
                        break;

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

                    default:
                        break;
                    }
                    break;

                default:
                    break;
                }
            }


            Console.WriteLine(car.ToString());
            Console.WriteLine(truck.ToString());
        }
Esempio n. 16
0
        public static void Main(string[] args)
        {
            string inputCarInformation  = Console.ReadLine();
            var    listOfCarInformation = inputCarInformation
                                          .Split(new[] { ' ' })
                                          .ToList();
            Car    car = new Car(double.Parse(listOfCarInformation[1]), double.Parse(listOfCarInformation[2]));
            string inputTruckInformation  = Console.ReadLine();
            var    listOfTruckInformation = inputTruckInformation
                                            .Split(new[] { ' ' })
                                            .ToList();
            Truck truck  = new Truck(double.Parse(listOfTruckInformation[1]), double.Parse(listOfTruckInformation[2]));
            int   repeat = int.Parse(Console.ReadLine());

            for (int i = 0; i < repeat; i++)
            {
                string inputCommand   = Console.ReadLine();
                var    vehicleCommand = inputCommand
                                        .Split(new[] { ' ' })
                                        .ToList();

                switch (vehicleCommand[0])
                {
                case "Drive":
                    if (vehicleCommand[1] == "Car")
                    {
                        Console.WriteLine(car.Drive(double.Parse(vehicleCommand[2])));;
                    }
                    else if (vehicleCommand[1] == "Truck")
                    {
                        Console.WriteLine(truck.Drive(double.Parse(vehicleCommand[2])));;
                    }
                    break;

                case "Refuel":
                    if (vehicleCommand[1] == "Car")
                    {
                        car.Refuel(double.Parse(vehicleCommand[2]));
                    }
                    else if (vehicleCommand[1] == "Truck")
                    {
                        truck.Refuel(double.Parse(vehicleCommand[2]));
                    }
                    break;

                default:
                    break;
                }
            }

            Console.WriteLine($"{car:f2}");
            Console.WriteLine($"{truck:f2}");
        }
Esempio n. 17
0
        public static void Main()
        {
            var carArgs    = Console.ReadLine().Split();
            var truckArgs  = Console.ReadLine().Split();
            int linesCount = int.Parse(Console.ReadLine());

            var carFuelQuantity    = double.Parse(carArgs[1]);
            var carFuelConsumption = double.Parse(carArgs[2]);
            var car = new Car(carFuelQuantity, carFuelConsumption);

            var truckFuelQuantity    = double.Parse(truckArgs[1]);
            var truckFuelConsumption = double.Parse(truckArgs[2]);
            var truck = new Truck(truckFuelQuantity, truckFuelConsumption);

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

                var command = commandArgs[0];
                var type    = commandArgs[1];

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

                    if (type == "Car")
                    {
                        Console.WriteLine(car.Drive(distance));
                    }
                    else
                    {
                        Console.WriteLine(truck.Drive(distance));
                    }
                }
                else if (command == "Refuel")
                {
                    double fuel = double.Parse(commandArgs[2]);

                    if (type == "Car")
                    {
                        car.Refuel(fuel);
                    }
                    else
                    {
                        truck.Refuel(fuel);
                    }
                }
            }

            Console.WriteLine(car);
            Console.WriteLine(truck);
        }
Esempio n. 18
0
        static void Main(string[] args)
        {
            string[] carInput   = Console.ReadLine().Split();
            string[] truckInput = Console.ReadLine().Split();

            double carFuelQuantity = double.Parse(carInput[1]);
            double carPerKm        = double.Parse(carInput[2]);

            double truckFuelQuantity = double.Parse(truckInput[1]);
            double truckPerKm        = double.Parse(truckInput[2]);

            int   n     = int.Parse(Console.ReadLine());
            Car   car   = new Car(carFuelQuantity, carPerKm, 0.9);
            Truck truck = new Truck(truckFuelQuantity, truckPerKm, 1.6);

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

                string command      = vehicleCommand[0];
                string vehicleType  = vehicleCommand[1];
                double commandParam = double.Parse(vehicleCommand[2]);

                switch (command)
                {
                case "Drive":
                    if (vehicleType == "Car")
                    {
                        car.Drive(commandParam);
                    }
                    else if (vehicleType == "Truck")
                    {
                        truck.Drive(commandParam);
                    }
                    break;

                case "Refuel":
                    if (vehicleType == "Car")
                    {
                        car.Refuel(commandParam);
                    }
                    else if (vehicleType == "Truck")
                    {
                        truck.Refuel(commandParam);
                    }
                    break;
                }
            }

            Console.WriteLine($"Car: {car.FuelQuantity:f2}");
            Console.WriteLine($"Truck: {truck.FuelQuantity:f2}");
        }
Esempio n. 19
0
        private static string Drive(string command, double distance, Car car, Bus bus, Truck truck)
        {
            switch (command)
            {
            case "Car": return(car.Drive(distance));

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

            case "Bus": return(bus.Drive(distance));

            default: return("Unknown vehicle");
            }
        }
Esempio n. 20
0
        static void Main(string[] args)
        {
            var     carInput = Console.ReadLine().Split();
            Vehicle car      = new Car(
                double.Parse(carInput[1]),
                double.Parse(carInput[2]));

            var     truckInput = Console.ReadLine().Split();
            Vehicle truck      = new Truck(
                double.Parse(truckInput[1]),
                double.Parse(truckInput[2]));

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

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

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

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

                    if (vehicle == nameof(Car))
                    {
                        Console.WriteLine(car.Drive(distance));
                    }
                    else if (vehicle == nameof(Truck))
                    {
                        Console.WriteLine(truck.Drive(distance));
                    }
                }
                else if (command == "Refuel")
                {
                    double fuel = double.Parse(line[2]);

                    if (vehicle == nameof(Car))
                    {
                        car.Refuel(fuel);
                    }
                    else if (vehicle == nameof(Truck))
                    {
                        truck.Refuel(fuel);
                    }
                }
            }
            Console.WriteLine(car);
            Console.WriteLine(truck);
        }
Esempio n. 21
0
        static void Main(string[] args)
        {
            string[] carData = Console.ReadLine()
                               .Split();            //Car 15 0.3

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

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

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

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

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

                string type    = currentCmd[1];
                string command = currentCmd[0];
                double amount  = double.Parse(currentCmd[2]);

                if (type == nameof(Car))
                {
                    if (command == "Drive")
                    {
                        Console.WriteLine(car.Drive(amount));
                    }
                    else
                    {
                        car.Refuel(amount);
                    }
                }
                else if (type == nameof(Truck))
                {
                    if (command == "Drive")
                    {
                        Console.WriteLine(truck.Drive(amount));
                    }
                    else
                    {
                        truck.Refuel(amount);
                    }
                }
            }

            Console.WriteLine(car);
            Console.WriteLine(truck);
        }
Esempio n. 22
0
        static void doWork()
        {
            Console.WriteLine("This is the Vehicles Lab.");
            Console.WriteLine("==============================================================");
            Console.WriteLine("Journey by airplane:");
            Airplane myPlane = new Airplane();

            myPlane.StartEngine("Contact");
            myPlane.TakeOff();
            myPlane.Drive();
            myPlane.Land();
            myPlane.StopEngine("Whirr");
            Console.WriteLine("==============================================================");
            Console.WriteLine("Journey by car:");
            Car myCar = new Car();

            myCar.StartEngine("Brm brm");
            myCar.Accelerate();
            myCar.Drive();
            myCar.Brake();
            myCar.StopEngine("Phut phut");
            Console.WriteLine("==============================================================");
            Console.WriteLine("Journey by truck:");
            Truck tyra = new Truck();

            tyra.StartEngine("Vroom Vroom");
            tyra.Haul();
            tyra.Drive();
            tyra.Tows();
            tyra.StopEngine("Klunk Klunk");
            Console.WriteLine("==============================================================");
            Console.WriteLine("Journey by boat:");
            Boat Titantic = new Boat();

            Titantic.StartEngine("Swish Swish");
            Titantic.Sail();
            Titantic.Drive();
            Titantic.Floats();
            Titantic.StopEngine("Glug Glug");
            Console.WriteLine("==============================================================");
            Console.WriteLine("Testing polymorphism");
            Vehicle v = myCar;

            v.Drive();
            v = myPlane;
            v.Drive();
            v = tyra;
            v.Drive();
            Console.WriteLine("==============================================================");
        }
Esempio n. 23
0
        static void Main(string[] args)
        {
            string[] carInfo   = ConsoleRead();
            string[] truckInfo = ConsoleRead();
            Car      car       = CreateCar(carInfo);
            Truck    truck     = CreateTruck(truckInfo);


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

            for (int i = 0; i < numberofCommands; i++)
            {
                string[] commandInfo = ConsoleRead();
                string   command     = commandInfo[0];
                double   distance    = double.Parse(commandInfo[2]);
                double   litres      = double.Parse(commandInfo[2]);
                string   type        = commandInfo[1];

                switch (command)
                {
                case "Drive":
                    switch (type)
                    {
                    case "Car":
                        car.Drive(distance);
                        break;

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

                case "Refuel":
                    switch (type)
                    {
                    case "Car":
                        car.Refuel(litres);
                        break;

                    case "Truck":
                        truck.Refuel(litres);
                        break;
                    }
                    break;
                }
            }
            Console.WriteLine(car);
            Console.WriteLine(truck);
        }
Esempio n. 24
0
        public static void Main(string[] args)
        {
            string[] options             = Console.ReadLine().Split();
            var      carFuelQuantity     = double.Parse(options[1]);
            var      carConsumptionPerKm = double.Parse(options[2]);

            options = Console.ReadLine().Split();
            var truckFuelQuantity     = double.Parse(options[1]);
            var truckConsumptionPerKm = double.Parse(options[2]);

            Vehicle car   = new Car(carFuelQuantity, carConsumptionPerKm);
            Vehicle truck = new Truck(truckFuelQuantity, truckConsumptionPerKm);

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

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

                if (options[0] == "Drive")
                {
                    double kms = double.Parse(options[2]);

                    if (options[1] == "Car")
                    {
                        car.Drive(kms);
                    }
                    else if (options[1] == "Truck")
                    {
                        truck.Drive(kms);
                    }
                }
                else if (options[0] == "Refuel")
                {
                    double liters = double.Parse(options[2]);

                    if (options[1] == "Car")
                    {
                        car.AddFuel(liters);
                    }
                    else if (options[1] == "Truck")
                    {
                        truck.AddFuel(liters);
                    }
                }
            }

            Console.WriteLine($"Car: {car.FuelQuantity:f2}");
            Console.WriteLine($"Truck: {truck.FuelQuantity:f2}");
        }
Esempio n. 25
0
        private static void DriveVehicleCheck(Car car, Truck truck, string[] cmdInput, string type)
        {
            if (type == "Car")
            {
                double distance = double.Parse(cmdInput[2]);
                Console.WriteLine(car.Drive(distance));
            }

            else if (type == "Truck")
            {
                double distance = double.Parse(cmdInput[2]);
                Console.WriteLine(truck.Drive(distance));
            }
        }
Esempio n. 26
0
        static void Main()
        {
            var carInfo = Console.ReadLine()
                          .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var truckInfo = Console.ReadLine()
                            .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

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

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

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

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

                    case "Truck":
                        truck.Drive(double.Parse(command[2]));
                        break;
                    }
                    break;

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

                    case "Truck":
                        truck.Refueled(double.Parse(command[2]));
                        break;
                    }
                    break;
                }
            }

            Console.WriteLine($"Car: {car.FuelQuantity:F2}");
            Console.WriteLine($"Truck: {truck.FuelQuantity:F2}");
        }
Esempio n. 27
0
        static void Main(string[] args)
        {
            string[] carMetricks  = Console.ReadLine().Split();
            double   fuelQuantity = double.Parse(carMetricks[1]);
            double   litersPerKm  = double.Parse(carMetricks[2]);

            Car car = new Car(fuelQuantity, litersPerKm);

            string[] truckMetricks = Console.ReadLine().Split();
            fuelQuantity = double.Parse(truckMetricks[1]);
            litersPerKm  = double.Parse(truckMetricks[2]);

            Truck truck = new Truck(fuelQuantity, litersPerKm);

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

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

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

                case "Refuel":
                    if (command[1] == "Car")
                    {
                        car.Refuel(double.Parse(command[2]));
                    }
                    else
                    {
                        truck.Refuel(double.Parse(command[2]));
                    }
                    break;
                }
            }

            Console.WriteLine(car);
            Console.WriteLine(truck);
        }
Esempio n. 28
0
        private static void ExecuteAction(Car car, Truck truck, Bus bus, string action, string vehicleType, double argument)
        {
            switch (action)
            {
            case "Drive":
                if (vehicleType == "Car")
                {
                    Console.WriteLine(car.Drive(argument));
                }
                else if (vehicleType == "Truck")
                {
                    Console.WriteLine(truck.Drive(argument));
                }
                else if (vehicleType == "Bus")
                {
                    Console.WriteLine(bus.Drive(argument, Bus.increasedFuelConsumption));
                }
                break;

            case "DriveEmpty":
                if (vehicleType == "Bus")
                {
                    Console.WriteLine(bus.Drive(argument));
                }
                break;

            case "Refuel":
                if (argument <= 0)
                {
                    Console.WriteLine("Fuel must be a positive number");
                }
                else
                {
                    if (vehicleType == "Car")
                    {
                        car.Refuel(argument);
                    }
                    else if (vehicleType == "Truck")
                    {
                        truck.Refuel(argument);
                    }
                    else if (vehicleType == "Bus")
                    {
                        bus.Refuel(argument);
                    }
                }
                break;
            }
        }
Esempio n. 29
0
        public void Run()
        {
            var carInfo         = Console.ReadLine().Split();
            var carFuelQuantity = double.Parse(carInfo[1]);
            var carLitersPerKm  = double.Parse(carInfo[2]);

            var car = new Car(carFuelQuantity, carLitersPerKm);

            var truckInfo         = Console.ReadLine().Split();
            var truckFuelQuantity = double.Parse(truckInfo[1]);
            var truckLitersPerKm  = double.Parse(truckInfo[2]);

            var truck = new Truck(truckFuelQuantity, truckLitersPerKm);

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

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

                if (command[0] == "End")
                {
                    break;
                }
                else if (command[0] == "Drive" && command[1] == "Car")
                {
                    var kilometersToDrive = double.Parse(command[2]);
                    car.Drive(kilometersToDrive);
                }
                else if (command[0] == "Refuel" && command[1] == "Car")
                {
                    var fuel = double.Parse(command[2]);
                    car.Refuel(fuel);
                }
                else if (command[0] == "Drive" && command[1] == "Truck")
                {
                    var kilometersToDrive = double.Parse(command[2]);
                    truck.Drive(kilometersToDrive);
                }
                else if (command[0] == "Refuel" && command[1] == "Truck")
                {
                    var fuel = double.Parse(command[2]);
                    truck.Refuel(fuel);
                }
            }
            Console.WriteLine($"Car: {car.FuelQuantity:f2}");
            Console.WriteLine($"Truck: {truck.FuelQuantity:f2}");
        }
Esempio n. 30
0
        public static void Main()
        {
            string[] carArgs = Console.ReadLine()
                               .Split();
            string[] truckArgs = Console.ReadLine()
                                 .Split();

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

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

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

                string command          = inputArgs[0];
                string vehicleType      = inputArgs[1];
                double distanceOrLiters = double.Parse(inputArgs[2]);

                if (command == "Drive")
                {
                    if (vehicleType == "Car")
                    {
                        Console.WriteLine(car.Drive(distanceOrLiters));
                    }
                    else if (vehicleType == "Truck")
                    {
                        Console.WriteLine(truck.Drive(distanceOrLiters));
                    }
                }
                else if (command == "Refuel")
                {
                    if (vehicleType == "Car")
                    {
                        car.Refuel(distanceOrLiters);
                    }
                    else if (vehicleType == "Truck")
                    {
                        truck.Refuel(distanceOrLiters);
                    }
                }
            }

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