Example #1
0
        static void DriveVehicle(Vehicle vehicle, double value)
        {
            bool canTravell = vehicle.Drive(value);

            string result =
                !canTravell
                ? $"{vehicle.GetType().Name} needs refueling"
                : $"{vehicle.GetType().Name} travelled {value} km";

            Console.WriteLine(result);
        }
        static void DriveVehicle(Vehicle vehicle, double value)
        {
            bool canTravel = vehicle.Drive(value);

            string result = !canTravel
                ? $"{vehicle.GetType().Name} needs refueling"
                : $"{vehicle.GetType().Name} travelled {value} km";

            Console.WriteLine(result);
            //if travelledDistance is 0, stringresult is "needs refueling", else -the second message
        }
Example #3
0
 private static void ProcessCommand(Vehicle vehicle, string command, double ammount)
 {
     if (command == "Drive")
     {
         vehicle.Drive(ammount);
         Console.WriteLine($"{vehicle.GetType().Name} travelled {ammount} km");
     }
     else if (command == "DriveEmpty")
     {
         ((Bus)vehicle).DriveEmpty(ammount); // to do ako gramne ne setva off na AirCond
         Console.WriteLine($"{vehicle.GetType().Name} travelled {ammount} km");
     }
     else if (command == "Refuel")
     {
         vehicle.Refuel(ammount);
     }
 }
Example #4
0
        public static void CanDrive(Vehicle vehicle, double distance)
        {
            bool   canDrive    = vehicle.CanDrive(distance);
            string vehicleType = vehicle.GetType().Name;
            string result      = canDrive ? $"{vehicleType} travelled {distance} km" : $"{vehicleType} needs refueling";

            Console.WriteLine(result);
        }
Example #5
0
        private static void ProcessCommand(Vehicle vehicle, string command, double parameter)
        {
            if (command == "Drive")
            {
                vehicle.Drive(parameter);

                Console.WriteLine($"{vehicle.GetType().Name} travelled {parameter} km");
            }
            else if (command == "DriveEmpty")
            {
                ((Bus)vehicle).TurnOffAirCondition();

                vehicle.Drive(parameter);

                ((Bus)vehicle).TurnOnAirCondition();
                Console.WriteLine($"{vehicle.GetType().Name} travelled {parameter} km");
            }
            else
            {
                vehicle.Refuel(parameter);
            }
        }
Example #6
0
        public static void Drive(Vehicle vehicle, double distance)
        {
            bool   canDrive    = vehicle.CanDrive(distance);
            string vehicleType = vehicle.GetType().Name;

            if (canDrive)
            {
                Console.WriteLine($"{vehicleType} travelled {distance} km");
            }
            else
            {
                Console.WriteLine($"{vehicleType} needs refueling");
            }
        }
        public static string CallMethod(string[] info, Vehicle vehicle)
        {
            string methodName = info[0];
            double param      = double.Parse(info[2]);
            string result     = null;

            try
            {
                result = vehicle.GetType().GetMethod(methodName).Invoke(vehicle, new object[] { param }).ToString();
            }
            catch (Exception e)
            {
                return(e.InnerException.Message);
            }
            return(result);
        }
Example #8
0
        static void Main(string[] args)
        {
            List <Vehicle> myVehicles = new List <Vehicle>();

            Car      myCar   = new Car(100, 5, "P 1234 AG");
            Boat     myBoat  = new Boat(50, 8, "Bulgaria");
            Airplane myPlane = new Airplane(1000, 64, "BA 195AF");

            myVehicles.Add(myCar);
            myVehicles.Add(myBoat);
            myVehicles.Add(myPlane);

            foreach (var item in myVehicles)
            {
                Console.WriteLine(item.GetInfo());
            }
            Console.WriteLine();

            Console.WriteLine("Index to Check:");
            int     index   = int.Parse(Console.ReadLine());
            Vehicle vehicle = myVehicles[index];

            Console.WriteLine($"Object at Index: {index} is a {vehicle.GetType().Name}.");

            if (vehicle is Car)
            {
                Console.Write("The Car's Registration is: ");
                Console.WriteLine(((Car)vehicle).Registration);
            }
            else if (vehicle is Boat)
            {
                Console.Write("The Boat's Nationality is: ");
                Console.WriteLine(((Boat)vehicle).Nationality);
            }
            else if (vehicle is Airplane)
            {
                Console.Write("The Plane's Callsign is: ");
                Console.WriteLine(((Airplane)vehicle).Callsign);
            }

            Console.ReadLine();
        }
Example #9
0
 private static void PrintVehicle(Vehicle vehicle)
 {
     Console.WriteLine($"{vehicle.GetType().Name}: {vehicle.FuelQuantity:F2}");
 }