Esempio n. 1
0
        static void Laba6Test()
        {
            Console.WriteLine("Lets create 3 cars:");

            Car car1 = new BMW("BMW X6", CarType.Crossover, DriveType.FourWhell);
            Car car2 = new Audi("Audi A8", DateTime.Now, CarType.Sedan, DriveType.FrontWhell);

            ElectricCar tesla = new ElectricCar("Tesla S", DateTime.Now, CarType.Crossover, DriveType.FourWhell);

            Console.WriteLine("Convert 1st car to String : " + car1.ToString());

            Engine engine  = new Engine(EngineType.diesel, 200, 12);
            Engine eEngine = new Engine(EngineType.electric, 200, 12);

            car1.Engine = engine;
            car2.Engine = engine;

            tesla.Engine = eEngine;

            Console.WriteLine("Move bmw:");
            car1.Move();
            Console.WriteLine("Move audi:");
            car2.Move();
            Console.WriteLine("Move tesla:");
            tesla.Move();

            car1.TurnEngineOff();
            car2.TurnEngineOff();
            tesla.TurnEngineOff();

            Console.WriteLine("{0} vs {1}\n{2} - won!Congratulations!", car1.UniqueID, tesla.UniqueID, ((Car)car1.CompeteWith(tesla)).UniqueID);
        }
Esempio n. 2
0
        static void Laba3and5Test()
        {
            Console.WriteLine("Lets create 3 cars:");

            Vehicle car1 = new Audi("Audi A5", CarType.Crossover, DriveType.FourWhell);
            Car     car2 = new Car("Noname car", CarType.Minivan, DriveType.FourWhell);
            Car     car3 = new Audi("Audi A8", DateTime.Now, CarType.Sedan, DriveType.FrontWhell);

            Console.WriteLine("Number of vehicles created = {0}", Vehicle.NumOfVehicles);

            Console.WriteLine(car1.ToString());
            Console.WriteLine(car2.ToString());
            Console.WriteLine(car3.ToString());

            Console.WriteLine("Try to turn engine on but engine is not installed:");

            try
            {
                car1.TurnEngineOn();
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR = {0}", ex.Message);
            }

            car1.Engine = new Engine(EngineType.diesel, 200, 12);
            Console.WriteLine("Now install the engine in the car:");

            try
            {
                car1.TurnEngineOn();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.WriteLine("Turn engine off:");
            car1.TurnEngineOff();
        }