static void Main(string[] args)
        {
            Automobile AudiA7 = new Automobile("130000 lv.", "8 L/100 km.");
            Automobile BMW740 = new Automobile("120000 lv.", "8 L/100 km.");
            Automobile MaseratiGranCabrio = new Automobile("250000 lv.", "14.5 L/100 km.");
            Automobile HyundaiI30 = new Automobile("25000 lv.", "6 L/100 km.");
            Automobile GreatWallC30 = new Automobile("22000 lv.", "7 L/100 km.");
            SUV InfinitiQX50 = new SUV("80000 lv.", true);
            SUV VolkswagenTouareg = new SUV("90000 lv.", true);
            SUV PorscheCayenne = new SUV("100000 lv.", true);
            SUV ToyotaLandCruiser = new SUV("90000 lv.", true);
            SUV MercedesGLK = new SUV("80000 lv.", true);

            Car[] array = new Car[]
            {
                AudiA7, BMW740, MaseratiGranCabrio, HyundaiI30, GreatWallC30, InfinitiQX50,
                VolkswagenTouareg, PorscheCayenne, ToyotaLandCruiser, MercedesGLK
            };

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

            //Console.WriteLine(HyundaiI30);
        }
Exemple #2
0
 public void CannotCreateCarWithNegativeTank()
 {
     Assert.Catch(() =>
     {
         var x = new Car(true, "blue", -50);
     });
 }
Exemple #3
0
 public void CannotCreateCarWithEmptyColor()
 {
     Assert.Catch(() =>
     {
         var x = new Car( true,"", 50);
     });
 }
Exemple #4
0
        static void Main(string[] args)
        {
            Car a = new Car(true, "blue", 50);
            Car b = new Car(false, "red", 40);
            Car c = new Car(false, "red", 20);
            Motorbike d = new Motorbike("green", 60);

            vehicle [] v= new vehicle[] {a,b,c,d};
            for (var i = 0; i < 4; i++)
            {
               Console.WriteLine(v[i].Look);
            }

            Serialization.Run(v);

            Console.WriteLine("Tankgrösse Auto a:"+ a.Tank);
            Console.WriteLine("Farbe von Auto a:"+ a.Color);
            Console.WriteLine("Trebstoffart von Auto b:" + b.Fuel);
            Console.WriteLine("Farbe von Auto b:"+ b.Color);

            Console.WriteLine("Farbe von Auto c:"+ (c.Color = "yellow"));
            Console.WriteLine("tanken von Auto a, Kosten:"+ a.FillUp(true,50));

            Console.WriteLine("Tankgrösse Auto c:" + c.Tank);
            c.ChangeTank(55);
            Console.WriteLine("Neue Tankgrösse Auto c:" + c.Tank);

            Console.WriteLine(a.Look);

            Console.WriteLine("Farbe " + d.Color);
            Console.WriteLine("Tank " + d.Tank);
        }
Exemple #5
0
 public void CannotUpdateCarWithNegativeTank()
 {
     Assert.Catch(() =>
     {
         var x = new Car(true, "blue", 50);
         x.ChangeTank(-10);
     });
 }
Exemple #6
0
        public void CanCreateCar()
        {
            var x = new Car(true, "blue", 50);

            Assert.IsTrue(x.Color == "blue");
            Assert.IsTrue(x.Fuel == true);
            Assert.IsTrue(x.Tank == 50);
        }
Exemple #7
0
        static void Main(string[] args)
        {
            Car[] Cars = new Car[10];
            for (int i = 0; i < Cars.Length / 2; i++)
            {
                Console.WriteLine("Enter price and fuelconsumption:");
                Cars[i] = new Automobile();
                (Cars[i] as Automobile).Price = int.Parse(Console.ReadLine());
                (Cars[i] as Automobile).FuelConsumption = int.Parse(Console.ReadLine());
                (Cars[i] as Automobile).CarInfo();
            }
            for (int i = Cars.Length / 2; i < Cars.Length; i++)
            {
                Console.WriteLine("Enter price and is 4x4:");
                Cars[i] = new SUV();
                (Cars[i] as SUV).Price = int.Parse(Console.ReadLine());
                (Cars[i] as SUV).HighlyPassable = bool.Parse(Console.ReadLine());
                (Cars[i] as SUV).SUVInfo();

            }
        }
Exemple #8
0
 public Traffic(Car c)
 {
     this.car = c;
     car.OnSpeed += new Car.ExcessSpeedEventHandler (OnSpeedWarning);
 }
Exemple #9
0
        public static void Main(string[] args)
        {
            Car c = new Car (5, 80);
            Traffic tr = new Traffic (c);

            for (int i = 0; i < 300; i = i + 10) {
                    Console.WriteLine ("{0}", c.Speed);
                c.Accelerate (10);
                Console.ReadLine ();
            }
        }
Exemple #10
0
        static void Main(string[] args)
        {
            ////Console.WriteLine(Engine.Lp100Km2MPG(6.4));
            //Engine e1 = new Engine(1480, 40);
            //Engine e2 = new Engine(2000, 60, 80);

            //Car suburau = new Car("subaru", "Impreza", new Engine(2.0, 20));
            //suburau.Go(150);

            //car mercedes = new car("mercedes", "C180", new Engine(1.8, 40));
            //mercedes.GO(100);

            string CarModel, CarType;
            double EngineCapacity, TankCapacity, UserAnswer, AddFuel;
            int    Distance;

            //------------collecting data from users------throw exception while collecting data------
            Console.Write("Please insert the car type : ");
            CarType = Console.ReadLine();

            Console.Write("Please insert the car model : ");
            CarModel = Console.ReadLine();

            //--------------------------check the Engine capcity-------------------------
            while (true)
            {
                Console.Write("Please insert Engine capacity of the car (in CC): ");
                if ((double.TryParse(Console.ReadLine(), out EngineCapacity) && (EngineCapacity > 0.5) && (EngineCapacity < 8.0)))
                {
                    break;
                }
                Console.WriteLine("please choose the correct value");
            }



            while (true)
            {
                Console.Write("Please insert the capcity of the car (in litre): ");
                if ((double.TryParse(Console.ReadLine(), out TankCapacity) && (TankCapacity > 20) && (TankCapacity < 100)))
                {
                    break;
                }
                Console.WriteLine("please choose the correct value");
            }

            Car NewCar = new Car(CarType, CarModel, new Engine(EngineCapacity, TankCapacity));



            while (true)
            {
                Console.WriteLine("What do you want to do with the car ? \n(please choose one number from the following)" +
                                  "\n 1. Ride the car. \n 2. fuel the car \n 3. exit the program. ");
                try
                {
                    UserAnswer = int.Parse(Console.ReadLine());
                    break;
                }
                catch (Exception)
                {
                    Console.WriteLine("invalid value, please insert the correct one.");
                }
            }


            if (UserAnswer == 1)
            {
                Console.Write("How far do you need to go (in Km)?");
                Distance = int.Parse(Console.ReadLine());
                try
                {
                    NewCar.Go(Distance);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            else if (UserAnswer == 2)
            {
                while (true)
                {
                    Console.Write("How many litre do you want to add?");
                    try
                    {
                        AddFuel = double.Parse(Console.ReadLine());
                        if (AddFuel < TankCapacity)
                        {
                            Console.WriteLine("Adding fuel in prgress.");
                        }
                        else
                        {
                            throw new ArgumentException("the fuel will split on the floor");
                        }
                        break;
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("invalid value, please insert the correct one.");
                    }
                }
            }
            else if (UserAnswer == 3)
            {
                Console.WriteLine("Good Bye Knba");
            }
            else
            {
                Console.WriteLine("UWAGA: insert the correct number.");
            }
        }