コード例 #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("escribe el tipo de auto");
            Console.WriteLine("las opciones son 0, 1, 2");
            int carType = Convert.ToInt32(Console.ReadLine().Trim());

            while (carType < 0 || carType > 2)
            {
                Console.WriteLine("numero equivocado");
                Console.WriteLine("el tipo de auto solamente puede ser 0, 1, 2");
                carType = Convert.ToInt32(Console.ReadLine().Trim());
            }

            Console.WriteLine("escribe la cantidad de kilometros");
            Console.WriteLine("las opciones van desde 5 hasta 30");
            int carMileage = Convert.ToInt32(Console.ReadLine().Trim());

            while (carMileage < 5 || carMileage > 30)
            {
                Console.WriteLine("numero equivocado");
                Console.WriteLine("las opciones van desde 5 hasta 30");
                carMileage = Convert.ToInt32(Console.ReadLine().Trim());
            }

            if (carType == 0)
            {
                Car wagonR = new WagonR(carMileage);
                wagonR.printCar("WagonR");
            }

            if (carType == 1)
            {
                Car hondaCity = new HondaCity(carMileage);
                hondaCity.printCar("HondaCity");
            }

            if (carType == 2)
            {
                Car innovaCrysta = new InnovaCrysta(carMileage);
                innovaCrysta.printCar("InnovaCrysta");
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            int carType    = Convert.ToInt32(Console.ReadLine().Trim());
            int carMileage = Convert.ToInt32(Console.ReadLine().Trim());

            if (carType == 0)
            {
                Car wagonR = new WagonR(carMileage);
                wagonR.printCar("WagonR");
            }

            if (carType == 1)
            {
                Car hondaCity = new HondaCity(carMileage);
                hondaCity.printCar("HondaCity");
            }

            if (carType == 2)
            {
                Car innovaCrysta = new InnovaCrysta(carMileage);
                innovaCrysta.printCar("InnovaCrysta");
            }
        }