コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Stanislav1996/C-sharp
        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();

            }
        }
コード例 #3
0
        static void Main(string[] args)
        {
            string[] brand = new string[10];

            for (int i = 0; i < brand.Length; i++)
            {
                if (i >= 0 && i <= 4)
                {
                    Console.Write("Enter automobile brand: ");
                    brand[i] = Console.ReadLine();
                }
                if (i > 4 && i < brand.Length)
                {
                    Console.Write("Enter SUV brand: ");
                    brand[i] = Console.ReadLine();
                }
            } Console.WriteLine();

            int[] price = new int[10];

            for (int i = 0; i < price.Length; i++)
            {
                Console.Write("Enter price for every vehicle: ");
                price[i] = int.Parse(Console.ReadLine());
            } Console.WriteLine();

            float[] consumption = new float[10];

            for (int i = 0; i < consumption.Length; i++)
            {
                Console.Write("Enter average fuel consumption: ");
                consumption[i] = float.Parse(Console.ReadLine());
            } Console.WriteLine();

            Console.WriteLine("Vehicles Info:");

            for (int i = 0; i < 10; i++)
            {
                if (i >= 0 && i <= 4)
                {
                    Automobile carInfo = new Automobile(price[i], consumption[i]);
                    carInfo.Price = price[i];
                    carInfo.FuelConsumption = consumption[i];

                    Console.WriteLine("Brand of automobile: " + brand[i]);
                    Console.WriteLine("Price: " + carInfo.Price + " EUR");
                    Console.WriteLine("Fuel consumption: " + carInfo.FuelConsumption);
                    Console.WriteLine();
                }
                if (i > 4 && i < 10)
                {
                    bool highRoad = true;

                    SUV carInfo = new SUV(price[i], highRoad);
                    carInfo.Price = price[i];
                    carInfo.HighRoad = highRoad;

                    if (consumption[i] < 10)
                    {
                        carInfo.HighRoad = false;
                        Console.WriteLine("Brand of SUV: " + brand[i]);
                        Console.WriteLine("Price: " + carInfo.Price + " EUR");
                        Console.WriteLine("High road: " + carInfo.HighRoad);
                    }
                    if (consumption[i] >= 10)
                    {
                        carInfo.HighRoad = true;
                        Console.WriteLine("Brand of SUV: " + brand[i]);
                        Console.WriteLine("Price: " + carInfo.Price + " EUR");
                        Console.WriteLine("High road: " + carInfo.HighRoad);
                    } Console.WriteLine();
                }
            }
        }