Example #1
0
        private static void Exercise9()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 9:", useReadLine: false);

            for (int forIndex = 0; forIndex < 100; forIndex++)
            {
                ConsoleAppPrintUtil.PrintText($"ForLoop - {forIndex + 1} - No lanzaré avioncitos de papel en clase.", useConsoleClear: false, useReadLine: false);
            }

            int doIndex = 0;

            do
            {
                ConsoleAppPrintUtil.PrintText($"DoLoop - {doIndex + 1} - No lanzaré avioncitos de papel en clase.", useConsoleClear: false, useReadLine: false);
                doIndex++;
            } while (doIndex < 100);

            int whileIndex = 0;

            while (whileIndex < 100)
            {
                ConsoleAppPrintUtil.PrintText($"WhileLoop - {whileIndex + 1} - No lanzaré avioncitos de papel en clase.", useConsoleClear: false, useReadLine: false);
                whileIndex++;
            }

            ConsoleAppPrintUtil.PrintText("Ciclos terminados.", useConsoleClear: false);
        }
Example #2
0
        private static void Exercise4()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 4:");

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

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

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

            try
            {
                var result = number1 / number2;
                ConsoleAppPrintUtil.PrintText($"El resultado de la división es: {result}");
            }
            catch (DivideByZeroException)
            {
                ConsoleAppPrintUtil.PrintText("La división entre cero no está definida.");
            }
            catch (Exception)
            {
                ConsoleAppPrintUtil.PrintText("Ocurrió un error inesperado.");
            }
        }
Example #3
0
        private static void Exercise1()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 1:", useReadLine: false);

            ConsoleAppPrintUtil.PrintText("Complete los datos restantes del alumno 1:", useConsoleClear: false);

            var questions = new string[] {
                "¿Cuáles son tus apellidos?",
                "¿Qué edad tienes?",
                "¿Cuál es tu nombre?"
            };

            var student1 = GetStudentWithoutName(questions);

            student1.Name = "Alumno 1";

            ConsoleAppPrintUtil.PrintText($"Los datos del alumno 1 son > {student1}.");

            ConsoleAppPrintUtil.PrintText("Complete los datos del alumno 2:");

            var student2 = GetStudentWithoutName(questions);

            student2.Name = ConsoleAppPrintUtil.PrintQuestionWithStringAnswerRecursive(questions[2]);

            ConsoleAppPrintUtil.PrintText($"Los datos del alumno 2 son > {student2}.");
        }
Example #4
0
        private static void Exercise20()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 29:");
            var foundNumber    = false;
            var breakCondition = false;
            var random         = new Random();
            var numberToFound  = random.Next(1, 100);

            do
            {
                var number = ConsoleAppPrintUtil.PrintQuestionWithIntPositiveOrNegativeAnswerRecursive("Introduzca un número:");
                if (number < 0)
                {
                    breakCondition = true;
                }
                else if (number < numberToFound)
                {
                    ConsoleAppPrintUtil.PrintText($"Lo siento, pero el número está por encima del valor introducido.");
                }
                else if (number > numberToFound)
                {
                    ConsoleAppPrintUtil.PrintText($"Lo siento, pero el número está por debajo del valor introducido.");
                }
                else
                {
                    foundNumber = true;
                }
            } while (!foundNumber && !breakCondition);

            ConsoleAppPrintUtil.PrintText(GetExercise20Text(foundNumber));
        }
Example #5
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();
            }
        }
Example #6
0
        private static void Exercise8()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 8:", useReadLine: false);

            ConsoleAppPrintUtil.PrintText("Introduzca 10 notas.", useConsoleClear: false);

            var notes = ConsoleAppUtil.GetArrayListOfNumbersLessThan(10, "Nota", 10);

            var approvedNote  = new ArrayList();
            var suspendedNote = new ArrayList();

            foreach (int note in notes)
            {
                if (note <= 5)
                {
                    suspendedNote.Add(note);
                }
                else
                {
                    approvedNote.Add(note);
                }
            }

            ConsoleAppPrintUtil.PrintText(GetExercise8Text(notes, approvedNote, suspendedNote));
        }
Example #7
0
        private static void Exercise2()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 2:");
            try
            {
                var questions = new string[] {
                    "Introduce un número de día entre 1 y 365: "
                };

                var numberOfDays = ConsoleAppPrintUtil.PrintQuestionWithIntPositiveOrNegativeAnswerRecursive(questions[0]);

                if (numberOfDays < 1 || numberOfDays > 365)
                {
                    throw new ArgumentOutOfRangeException($"Día fuera de intervalo");
                }

                var daysInMonths = new int[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
                var monthNumber  = Exercise2GetMonthNumber(daysInMonths, ref numberOfDays);

                ConsoleAppPrintUtil.PrintText($"Día: {numberOfDays} - Mes: { (MountNameEnum)monthNumber }");
            }
            catch (Exception caught)
            {
                Console.WriteLine($"Excepción controlada: {caught}");
                Console.Read();
            }
        }
Example #8
0
        private static void Exercise4()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 4:", useReadLine: false);

            ConsoleAppPrintUtil.PrintText("Complete los datos del alumno:", useConsoleClear: false);

            var questions = new string[] {
                "¿Cuáles son tus apellidos?",
                "¿Qué edad tienes?",
                "¿Cuál es tu nombre?",
                "¿Cuál es la nota del examen?",
                "¿Cuál es su género?"
            };

            var student = new Student
            {
                Name = ConsoleAppPrintUtil.PrintQuestionWithStringAnswerRecursive(questions[2]),

                LastName = ConsoleAppPrintUtil.PrintQuestionWithStringAnswerRecursive(questions[0]),

                Age = ConsoleAppPrintUtil.PrintQuestionWithIntAnswerLessThanRecursive(questions[1], 150),

                ExaminationNote = ConsoleAppPrintUtil.PrintQuestionWithIntAnswerLessThanRecursive(questions[3], 10),

                Sex = ConsoleAppPrintUtil.PrintQuestionWithCharAnswerRecursive(questions[4], correctAnswers: new string[] { "H", "M" })
            };

            ConsoleAppPrintUtil.PrintText($"Los datos del alumno son > {student}.");
        }
Example #9
0
        private static void Exercise3()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 3:", useReadLine: false);

            var dog = CreateDog(color: "negro", scientificName: "perro", alimentacion: FeedingEnum.Carnivoro, velocidad: 60);

            var cat = CreateCat(raza: "persa", scientificName: "perro", alimentacion: FeedingEnum.Carnivoro, velocidad: 40);

            Animal animal1 = dog;
            Animal animal2 = cat;

            var dogToString = animal1.ToString();
            var dogRun      = animal1.Run();
            var dogJump     = animal1.Jump();
            //var perroColor = animal1.Color; Es una propiedad de una de las especificaciones
            //var perroRaza = animal1.Raza; Es una propiedad de una de las especificaciones

            var catToString = animal2.ToString();
            var catRun      = animal2.Run();
            var catJump     = animal2.Jump();

            //var gatoColor = animal2.Color; Es una propiedad de una de las especificaciones
            //var gatoRaza = animal2.Raza; Es una propiedad de una de las especificaciones

            ConsoleAppPrintUtil.PrintText("Los objetos han sido creados y analizado su comportamiento.", useConsoleClear: false);
        }
Example #10
0
        private static void Exercise4()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 4:", useReadLine: false);

            var person1 = CreatePerson(name: "Persona 1", age: 50, sex: 'M');

            var person2 = CreatePerson(name: "Persona 2", age: 60, sex: 'M');

            var person3 = CreatePerson(name: "Persona 3", age: 70, sex: 'F');

            ConsoleAppPrintUtil.PrintText("Personas creadas: ", useConsoleClear: false, useReadLine: false);
            ConsoleAppPrintUtil.PrintWriteLineEmpty();

            ConsoleAppPrintUtil.PrintText(GetPersonText(person1), useConsoleClear: false, useReadLine: false);
            ConsoleAppPrintUtil.PrintText(GetPersonText(person2), useConsoleClear: false, useReadLine: false);
            ConsoleAppPrintUtil.PrintText(GetPersonText(person3), useConsoleClear: false, useReadLine: false);

            ConsoleAppPrintUtil.PrintWriteLineEmpty();

            var higherPerson = person1 > person2;

            ConsoleAppPrintUtil.PrintText($"Entre la persona 1 y 2 la mayor es: {higherPerson}", useConsoleClear: false, useReadLine: false);
            var lowerPerson = person1 < person3;

            ConsoleAppPrintUtil.PrintText($"Entre la persona 1 y 3 la menor es: {lowerPerson}", useConsoleClear: false, useReadLine: false);
            var equalsSex = person1 == person3 ? "Si" : "No";

            ConsoleAppPrintUtil.PrintText($"Las personas 1 y 3 tienen el mismo sexo: {equalsSex}", useConsoleClear: false, useReadLine: false);
            var differentSex = person2 != person3 ? "Si" : "No";

            ConsoleAppPrintUtil.PrintText($"Las personas 2 y 3 tienen diferentes sexo: {differentSex}", useConsoleClear: false);
        }
Example #11
0
        private static void Exercise4()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 4:");

            var noteExam = ConsoleAppPrintUtil.PrintQuestionWithIntAnswerLessThanRecursive("Introduce la nota del examen: ", 10);

            ConsoleAppPrintUtil.PrintText(GetExercise4Text(noteExam));
        }
Example #12
0
        private static void Exercise9()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 9:", useReadLine: false);

            var numbers = Exercise9GetNumbers();

            ConsoleAppPrintUtil.PrintText(GetExercise9Text(numbers));
        }
Example #13
0
        private static void Exercise18()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 18:");

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

            ConsoleAppPrintUtil.PrintText(GetExercise18Text(high));
        }
Example #14
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));
        }
Example #15
0
        private static void Exercise1()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 1:", useReadLine: false);

            var persona1 = CreatePersona(name: "Persona 1", lastName: "Apellidos", phoneNumber: "123456", email: "*****@*****.**", accreditation: AccreditationEnum.Institucional, sex: SexEnum.Femenino);

            var persona2 = CreatePersona(name: "Persona 2", lastName: "Apellidos", phoneNumber: "654321", email: "*****@*****.**", accreditation: AccreditationEnum.Especializada, sex: SexEnum.Masculino);

            ConsoleAppPrintUtil.PrintText(GetExercise1Text(persona1, persona2), useConsoleClear: false);
        }
Example #16
0
        private static void Exercise3()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 2:", useReadLine: false);

            var donut  = CreateDonut(19.45, true);
            var muffin = CreateMuffin(34.56, "Magdalena Premiun");
            var cake   = CreateCake(SizeEnum.Mediano, 5, "Feliz cumpleaños");

            ConsoleAppPrintUtil.PrintText(GetExercise3Text(donut, muffin, cake), useConsoleClear: false);
        }
Example #17
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));
        }
Example #18
0
        private static void Exercise6()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 6:");

            const string text1  = "Escriba una cadena para invertirla:";
            var          answer = ConsoleAppPrintUtil.PrintQuestionWithStringAnswerRecursive(text1);

            string answerReverse = ConsoleAppUtil.Reverse(answer);

            ConsoleAppPrintUtil.PrintText($"Cadena invertida: {answerReverse}");
        }
Example #19
0
        private static void Exercise7()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 7:", useReadLine: false);

            var numbers = new ArrayList(10)
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10
            };

            ConsoleAppPrintUtil.PrintText(GetExercise7Text(numbers), useConsoleClear: false);
        }
Example #20
0
        private static void Exercise2()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 2:");

            var numbers =
                ConsoleAppPrintUtil.PrintQuestionWithArrayListIntAnswerRecursive("Introduce diez números separados por una coma:", 10);

            numbers.Reverse();

            ConsoleAppPrintUtil.PrintText($"Los números introducidos en orden inverso fueron: {String.Join(",", numbers.ToArray())}");
        }
Example #21
0
        private static void Exercise7()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 7:", useReadLine: false);

            var academy = new Academy()
            {
                Classrooms = GetAulas(2)
            };

            ConsoleAppPrintUtil.PrintText(GetExercise7Text(academy));
        }
Example #22
0
        private static void Exercise1()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 1:", useReadLine: false);

            ConsoleAppPrintUtil.PrintText("Los objetos han sido creados:", useConsoleClear: false, useReadLine: false);

            var house = CreateHouse(surface: 100, plants: 2, habitations: 3, bedrooms: 2, bathrooms: 1);

            var office = CreateOffice(surface: 100, plants: 2, habitations: 3, fireExtinguishers: 1, phones: 1);

            ConsoleAppPrintUtil.PrintText(GetExercise1Text(house, office), useConsoleClear: false);
        }
Example #23
0
        private static void Exercise6()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 6:", useReadLine: false);

            var students = GetStudents(3, aula: 1);

            var classroom = new Classroom()
            {
                Students = students
            };

            ConsoleAppPrintUtil.PrintText(GetExercise6Text(classroom));
        }
Example #24
0
        private static void Exercise7()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 7:");

            const string text1        = "Path del fichero de lectura:";
            var          fileFromPath = ConsoleAppPrintUtil.PrintQuestionWithStringAnswerRecursive(text1);

            const string text2      = "Path del fichero de escritura:";
            var          fileToPath = ConsoleAppPrintUtil.PrintQuestionWithStringAnswerRecursive(text2);

            var transferData = ConsoleAppUtil.TransferDataFromFile(fileFromPath, fileToPath);

            Exercise7PrintText(transferData);
        }
Example #25
0
        private static void Exercise1()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 1:");

            const string phrase1 = "Apaga y vámonos.";
            const string phrase2 = "Coser y cantar.";
            const string phrase3 = "El quinto pino.";

            Console.WriteLine($"Frase 1: {phrase1}");
            Console.WriteLine($"Frase 2: {phrase2}");
            Console.WriteLine($"Frase 3: {phrase3}");

            Console.ReadLine();
        }
Example #26
0
        private static void Exercise5()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 5:", useReadLine: false);

            var random = new Random();

            var number1 = random.Next(10, 100);
            var number2 = random.Next(10, 100);
            var number3 = random.Next(10, 100);

            ConsoleAppPrintUtil.PrintText(GetExercise5PrintRandom(number1, number2, number3));

            ConsoleAppPrintUtil.PrintText(GetExercise5Text(number1, number2, number3));
        }
Example #27
0
        private static void Exercise10()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 10:");

            var number = ConsoleAppPrintUtil.PrintQuestionWithIntAnswerLessThanRecursive("Escribe un número entre 1 y 10: ", 10);

            ConsoleAppPrintUtil.PrintText($"Tabla de mutiplicar del {number}.", useReadLine: false);
            for (int i = 1; i <= 10; i++)
            {
                ConsoleAppPrintUtil.PrintText($"{number}x{i}={number * i}", useConsoleClear: false, useReadLine: false);
            }

            ConsoleAppPrintUtil.PrintText("", useConsoleClear: false);
        }
Example #28
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));
        }
Example #29
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)}");
        }
Example #30
0
        private static void Exercise1()
        {
            ConsoleAppPrintUtil.PrintTextWithLineSeparator("Ejercicio 1:");

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

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

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

            ConsoleAppPrintUtil.PrintDivision(number1, number2);
        }