Beispiel #1
0
        // returns a list with vehicles
        private static WrapperList CreateExampleListWithVehicles()
        {
            WrapperList list = new WrapperList();

            list.Add(new Car(150000, 180, 1998, "Sedan", "petrol", true));
            list.Add(new Car(250000, 230, 2013, "Sedan", "petrol"));
            list.Add(new Bicycle(1000, 35, 2015, "Standart", 15));
            list.Add(new Bicycle(300, 15, 1992, "Standart", 20));
            list.Add(new Lorry(10000000, 135, 2008, "Standart engine", 6));

            return(list);
        }
Beispiel #2
0
        private static void DemonstrationExample1()
        {
            // Examples1
            Console.WriteLine("\nEXAMPLES1\n\n");

            // TestEquals1
            Vehicle veh1 = new Car(15000, 200, 2012, "Sed", "Standart", true);
            Vehicle veh2 = new Car(15000, 200, 2012, "Sed", "Standart", true);

            Console.WriteLine("TestEquals1\n" + veh1 + "\n" + veh2 + "\nIsEquals = " + veh1.Equals(veh2) + "\n\n"); // True

            // TestEquals2
            veh2.MaxSpeed = 132;
            Console.WriteLine("TestEquals2\n" + veh1 + "\n" + veh2 + "\nIsEquals = " + (veh1 == veh2) + "\n\n");    // False

            // TestEquals3
            veh2 = new Bicycle(1000, 35, 2005, "Simple", 4);
            try
            {
                Console.WriteLine("TestEquals3\n" + veh1 + "\n" + veh2 + "\nIsEquals = " + veh1.Equals(veh2) + "\n\n"); // False
            }
            catch (MInvalidCastException exc)
            {
                Console.WriteLine("TestEquals3\n" + veh1 + "\n" + veh2 + "\nIsEquals = False(" + exc.Message + ")\n\n"); // False
            }

            // TestEquals4
            veh2 = (Vehicle)veh1.DeepCopy();
            Console.WriteLine("TestEquals4\n" + veh1 + "\n" + veh2 + "\nIsEquals = " + (veh1 == veh2) + "\n\n");    // True

            // Example2
            WrapperList vehicles = new WrapperList();

            vehicles.Add(veh1);
            vehicles.Add(veh2);
            vehicles.Add(new Bicycle(100, 300, 2002, "Sim", 2));

            Garage garage1 = new Garage(vehicles);
            Garage garage2 = new Garage(vehicles);

            // True
            Console.WriteLine("TestEquals5\n" + garage1 + "\n" + garage2 + "\nIsEquals = " + (garage1.Equals(garage2)) + "\n\n");

            // False
            garage2.AddVehicle(new Lorry(100200, 170, 2015, "EngineStandart", 6));
            Console.WriteLine("TestEquals6\n" + garage1 + "\n" + garage2 + "\nIsEquals = " + (garage1.Equals(garage2)) + "\n\n");

            // True
            garage2 = (Garage)garage1.DeepCopy();
            Console.WriteLine("TestEquals7\n" + garage1 + "\n" + garage2 + "\nIsEquals = " + (garage1.Equals(garage2)) + "\n\n");
        }
Beispiel #3
0
 // adding vehicle to garage
 public void AddVehicle(Vehicle vehicle)
 {
     garageVehicles.Add(vehicle);
 }