예제 #1
0
        private static void Exercise3()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 3:");
            try
            {
                var numberOfTheYear = ConsoleAppPrintUtil.PrintQuestionWithIntAnswerRecursive("Introduce un número de año: ");

                //if ((numberOfTheYear % 4 == 0) && (numberOfTheYear % 100 != 0 || numberOfTheYear % 400 == 0))
                //    ConsoleAppPrintUtil.PrintText("Es un año bisiesto");
                //else
                //    ConsoleAppPrintUtil.PrintText("NO es un año bisiesto");

                var isLeapYear = (numberOfTheYear % 4 == 0) && (numberOfTheYear % 100 != 0 || numberOfTheYear % 400 == 0);
                var maxOfDay   = isLeapYear ? 366 : 365;

                var numberOfDays = ConsoleAppPrintUtil.PrintQuestionWithIntPositiveOrNegativeAnswerRecursive($"Introduce un número de día entre 1 y {maxOfDay}: ");
                if (numberOfDays < 1 || numberOfDays > maxOfDay)
                {
                    throw new ArgumentOutOfRangeException($"Día fuera de intervalo");
                }

                var monthNumber = Exercise3MonthNumber(isLeapYear, ref numberOfDays);

                ConsoleAppPrintUtil.PrintText($"Día: {numberOfDays} - Mes: { (MountNameEnum)monthNumber }");
            }
            catch (Exception caught)
            {
                Console.WriteLine($"Excepción controlada: {caught}");
                Console.Read();
            }
        }
예제 #2
0
        private static void Exercise18()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 18:");

            var high = ConsoleAppPrintUtil.PrintQuestionWithIntAnswerRecursive("Introduzca el altura del triángulo:");

            ConsoleAppPrintUtil.PrintText(GetExercise18Text(high));
        }
예제 #3
0
        private static void Exercise16()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 16:");

            var high  = ConsoleAppPrintUtil.PrintQuestionWithIntAnswerRecursive("Introduzca el alto del rectángulo:");
            var width = ConsoleAppPrintUtil.PrintQuestionWithIntAnswerRecursive("Introduzca el ancho del rectángulo:");

            ConsoleAppPrintUtil.PrintText(GetExercise16Text(high, width));
        }
예제 #4
0
        private static void Exercise19()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 19:");

            var number = ConsoleAppPrintUtil.PrintQuestionWithIntAnswerRecursive("Introduzca un número:");

            bool isPrime = IsPrime(number);

            ConsoleAppPrintUtil.PrintText(GetExercise19Text(isPrime));
        }
예제 #5
0
        private static void Exercise13()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 13:");

            var number = ConsoleAppPrintUtil.PrintQuestionWithIntAnswerRecursive("Introduzca un número para multiplicarlo por los siguientes 5 números:");

            var multiply = 1M;

            for (int i = number; i < number + 5; i++)
            {
                multiply *= i;
            }

            ConsoleAppPrintUtil.PrintText($"El producto de {number} con sus siguientes 5 números es: {multiply}");
        }
예제 #6
0
        private static void Exercise12()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 12:");

            var cantNumbers = ConsoleAppPrintUtil.PrintQuestionWithIntAnswerRecursive("¿Cuántos números introducirás?");

            var sum = 0;

            for (int i = 0; i < cantNumbers; i++)
            {
                sum = sum + ConsoleAppPrintUtil.PrintQuestionWithIntAnswerRecursive($"Introduzca el número {i+1} de {cantNumbers}: ");
            }

            ConsoleAppPrintUtil.PrintText($"La suma de los números introducidos es: {sum}");
        }
예제 #7
0
        private static void Exercise11()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 11:");

            var number = ConsoleAppPrintUtil.PrintQuestionWithIntAnswerRecursive("Escribe un número: ");

            int factorial = 1;

            for (int i = 1; i <= number; i++)
            {
                factorial = factorial * i;
            }

            ConsoleAppPrintUtil.PrintText($"El factorial de {number} es: {factorial}");
        }
예제 #8
0
        private static void Exercise7()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 7:");

            var questions = new string[] {
                "¿En qué año estamos? ",
                "Escribe un año cualquiera: "
            };

            var year = ConsoleAppPrintUtil.PrintQuestionWithIntAnswerRecursive(questions[0]);

            var yearRandom = ConsoleAppPrintUtil.PrintQuestionWithIntAnswerRecursive(questions[1]);

            ConsoleAppPrintUtil.PrintText(GetExercise7Text(year, yearRandom));
        }
예제 #9
0
        private static void Exercise3()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 3:");

            var questions = new string[] {
                "Introduzca el primer valor de la operación:",
                "Introduzca el segundo valor de la operación:"
            };

            var number1 = ConsoleAppPrintUtil.PrintQuestionWithIntAnswerRecursive(questions[0]);

            var number2 = ConsoleAppPrintUtil.PrintQuestionWithIntAnswerRecursive(questions[1]);

            ConsoleAppPrintUtil.PrintText($"La suma entre dichos valores es: {number1 + number2}");
        }
예제 #10
0
        private static void Exercise5()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 5:");

            var questions = new string[] {
                "Nº de valores a introducir:",
                "Valor"
            };

            var countOfNumbers = ConsoleAppPrintUtil.PrintQuestionWithIntAnswerRecursive(questions[0]);

            var numbers = ConsoleAppUtil.GetArrayListOfNumbers(countOfNumbers);

            ConsoleAppPrintUtil.PrintText(GetExercise5Text(numbers));
        }
예제 #11
0
        private static void Exercise1()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 1:");

            var questions = new string[] {
                "Introduce primer número:",
                "Introduce segundo número:"
            };

            var number1 = ConsoleAppPrintUtil.PrintQuestionWithIntAnswerRecursive(questions[0]);

            var number2 = ConsoleAppPrintUtil.PrintQuestionWithIntAnswerRecursive(questions[1]);

            ConsoleAppPrintUtil.PrintText($"El valor mayor es: {ConsoleAppUtil.Max(number1, number2)}");
        }
예제 #12
0
        private static void Exercise6()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 6:");

            var questions = new string[] {
                "Nº de valores a introducir para cada serie:"
            };

            var countOfNumbers = ConsoleAppPrintUtil.PrintQuestionWithIntAnswerRecursive(questions[0]);

            var numbersOfSerie1 = ConsoleAppUtil.GetArrayListOfNumbers(countOfNumbers, text: "Serie 1 > Valor");

            var numbersOfSerie2 = ConsoleAppUtil.GetArrayListOfNumbers(countOfNumbers, text: "Serie 2 > Valor");

            ConsoleAppPrintUtil.PrintText(GetExercise6Text(numbersOfSerie1, numbersOfSerie2));
        }
예제 #13
0
        private static void Exercise4()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 4:");

            var number = ConsoleAppPrintUtil.PrintQuestionWithIntAnswerRecursive("Número para el factorial:");

            var hasFactorial = ConsoleAppUtil.TryFactorialRecursive(number, out int factorial);

            if (hasFactorial)
            {
                ConsoleAppPrintUtil.PrintText($"Factorial({number}) = {factorial} (recursivo)");
            }
            else
            {
                ConsoleAppPrintUtil.PrintText($"No se puede calcular el factorial de: {number} (recursivo)");
            }
        }
예제 #14
0
        private static void Exercise14()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 14:");

            var cantNumber = ConsoleAppPrintUtil.PrintQuestionWithIntAnswerRecursive("¿Cuántos números va a introducir?");

            var numbers = new List <int>();

            for (int i = 0; i < cantNumber; i++)
            {
                numbers.Add(ConsoleAppPrintUtil.PrintQuestionWithIntPositiveOrNegativeAnswerRecursive($"Introduzca el número {i + 1}:"));
            }

            var cantNegative = numbers.Count(number => number < 0);

            ConsoleAppPrintUtil.PrintText($"La cantidad de números negativos introducida es: {cantNegative}");
        }
예제 #15
0
        private static void Exercise8()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 8:");

            var questions = new string[] {
                "Escribe un número: ",
                "Escribe otro número: ",
                "Escribe otro número más: "
            };

            var number1 = ConsoleAppPrintUtil.PrintQuestionWithIntAnswerRecursive(questions[0]);

            var number2 = ConsoleAppPrintUtil.PrintQuestionWithIntAnswerRecursive(questions[1]);

            var number3 = ConsoleAppPrintUtil.PrintQuestionWithIntAnswerRecursive(questions[2]);

            ConsoleAppPrintUtil.PrintText(GetExercise8Text(number1, number2, number3));
        }
예제 #16
0
        private static void Exercise2()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 2:");

            var questions = new string[] {
                "Introduce primer número:",
                "Introduce segundo número:"
            };

            var number1 = ConsoleAppPrintUtil.PrintQuestionWithIntAnswerRecursive(questions[0]);

            var number2 = ConsoleAppPrintUtil.PrintQuestionWithIntAnswerRecursive(questions[1]);

            ConsoleAppPrintUtil.PrintText($"Antes del swap: x = {number1}, y = {number2}");

            ConsoleAppUtil.Swap(ref number1, ref number2);

            ConsoleAppPrintUtil.PrintText($"Después del swap: x = {number1}, y = {number2}");
        }
예제 #17
0
        private static void Exercise4()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 4:");

            var questions = new string[] {
                "¿Cómo te llamas?",
                "¿Cuántas horas has trabajado?",
                "¿Qué precio cobras por hora?"
            };

            var name = ConsoleAppPrintUtil.PrintQuestionWithStringAnswerRecursive(questions[0]);

            var hoursWorked = ConsoleAppPrintUtil.PrintQuestionWithIntAnswerRecursive(questions[1]);

            var priceByHour = ConsoleAppPrintUtil.PrintQuestionWithDecimalAnswerRecursive(questions[2]);

            var answerText = Exercise4GetAnswerText(name, hoursWorked, priceByHour);

            ConsoleAppPrintUtil.PrintText(answerText);
        }
예제 #18
0
        private static void Exercise2()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 2:");

            var answerOfQuestions = new List <object>();

            var questions = new string[] {
                "¿Cómo te llamas?",
                "¿Dónde vives?",
                "¿Cuántos años tienes?",
                "¿Te gusta el deporte?",
                "¿Hace calor hoy?"
            };

            var name = ConsoleAppPrintUtil.PrintQuestionWithStringAnswerRecursive(questions[0]);

            answerOfQuestions.Add(name);

            var address = ConsoleAppPrintUtil.PrintQuestionWithStringAnswerRecursive(questions[1]);

            answerOfQuestions.Add(address);

            var age = ConsoleAppPrintUtil.PrintQuestionWithIntAnswerRecursive(questions[2]);

            answerOfQuestions.Add(age);

            var likeSport = ConsoleAppPrintUtil.PrintQuestionWithCharAnswerRecursive(questions[3], correctAnswers: new string [] { "S", "N" });

            answerOfQuestions.Add(likeSport);

            var hotDay = ConsoleAppPrintUtil.PrintQuestionWithCharAnswerRecursive(questions[4], correctAnswers: new string[] { "S", "N" });

            answerOfQuestions.Add(hotDay);

            Exercise2ShowAnswerOfQuestions(answerOfQuestions);
        }