Beispiel #1
0
        static void Main(string[] args)
        {
            Aluno[] alunos       = new Aluno[5];
            var     indiceAluno  = 0;
            string  opcaoUsuario = ObterOpcaoUsuario();

            while (opcaoUsuario.ToUpper() != "X")
            {
                switch (opcaoUsuario)
                {
                case "1":
                    //todo: adcionar aluno e nota
                    Console.WriteLine("Informe o Nome do Aluno: ");
                    Aluno aluno = new Aluno();
                    aluno.Nome = Console.ReadLine();

                    Console.WriteLine("Informe a Sua Nota: ");
                    if (decimal.TryParse(Console.ReadLine(), out decimal nota))
                    {
                        aluno.nota = nota;
                    }
                    else
                    {
                        throw new ArgumentException("Valor  da nota  deve ser Decimal! ");
                    }
                    alunos[indiceAluno] = aluno;
                    indiceAluno++;
                    break;

                case "2":
                    //todo: lista aluno
                    foreach (var a in alunos)
                    {
                        if (!string.IsNullOrEmpty(a.Nome))
                        {
                            Console.WriteLine($"AlUNO: {a.Nome} - NOTA: {a.nota}");
                        }
                    }
                    break;

                case "3":
                    //todo: calcular media geral e conceito
                    decimal notaTotal = 0;
                    var     nrAlunos  = 0;

                    for (int i = 0; i < alunos.Length; i++)
                    {
                        if (!string.IsNullOrEmpty(alunos[i].Nome))
                        {
                            notaTotal = notaTotal + alunos[i].nota;
                            nrAlunos++;
                        }
                    }
                    var      mediaGeral = notaTotal / nrAlunos;
                    Conceito conceitoGeral;

                    if (mediaGeral < 2)
                    {
                        conceitoGeral = Conceito.E;
                    }
                    else if (mediaGeral < 4)
                    {
                        conceitoGeral = Conceito.D;
                    }

                    else if (mediaGeral < 6)
                    {
                        conceitoGeral = Conceito.C;
                    }

                    else if (mediaGeral < 8)
                    {
                        conceitoGeral = Conceito.B;
                    }

                    else
                    {
                        conceitoGeral = Conceito.A;
                    }


                    Console.WriteLine($"Media Geral: {mediaGeral} - CONCEITO: {conceitoGeral}");
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                opcaoUsuario = ObterOpcaoUsuario();
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Aluno[] alunos      = new Aluno[5];
            var     indiceAluno = 0;

            string opcaoUsuario = ObterOpcaoUser();

            while (opcaoUsuario.ToUpper() != "X")
            {
                switch (opcaoUsuario)
                {
                case "1":
                    Console.WriteLine("Informe o nome do aluno:");
                    Aluno aluno = new Aluno();
                    aluno.Nome = Console.ReadLine();
                    Console.WriteLine("Informe a nota do aluno:");

                    if (decimal.TryParse(Console.ReadLine(), out decimal nota))
                    {
                        aluno.Nota = nota;
                    }
                    else
                    {
                        throw new ArgumentException("O valor da nota deve ser decimal.");
                    }
                    alunos[indiceAluno] = aluno;
                    indiceAluno++;
                    Console.WriteLine("Deseja registrar outro aluno? S/N?");
                    string refazerCad = Console.ReadLine();
                    if (refazerCad.ToUpper() != "S")
                    {
                        break;
                    }
                    else
                    {
                        continue;
                    }

                case "2":
                    foreach (var student in alunos)
                    {
                        if (!string.IsNullOrEmpty(student.Nome))
                        {
                            Console.WriteLine($"ALUNO: {student.Nome} - NOTA: {student.Nota}");
                        }
                    }

                    break;

                case "3":
                    decimal notaTotal = 0;
                    var     nAlunos   = 0;
                    for (int i = 0; i < alunos.Length; i++)
                    {
                        if (!string.IsNullOrEmpty(alunos[i].Nome))
                        {
                            notaTotal = notaTotal + alunos[i].Nota;
                            nAlunos++;
                        }
                    }
                    var          mediaGeral = notaTotal / nAlunos;
                    ConceitoEnum conceitoGeral;
                    if (mediaGeral < 2)
                    {
                        conceitoGeral = ConceitoEnum.E;
                    }
                    else if (mediaGeral < 4)
                    {
                        conceitoGeral = ConceitoEnum.D;
                    }
                    else if (mediaGeral < 6)
                    {
                        conceitoGeral = ConceitoEnum.C;
                    }
                    else if (mediaGeral < 8)
                    {
                        conceitoGeral = ConceitoEnum.B;
                    }
                    else
                    {
                        conceitoGeral = ConceitoEnum.A;
                    }
                    Console.WriteLine($"Média Geral: {mediaGeral} CONCEITO - {conceitoGeral}");
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                opcaoUsuario = ObterOpcaoUser();
            }
        }