-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
105 lines (95 loc) · 4.27 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System;
namespace Revisao
{
class Program
{
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: Adicionar Alunos
Console.Write("Informe o nome do Aluno: ");
Aluno aluno = new Aluno();
aluno.Nome = Console.ReadLine();
Console.WriteLine();
Console.Write("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++;
break;
case "2":
//TODO: Listar Alunos
Console.Clear();
Console.WriteLine("Lista de Alunos e Notas:");
Console.WriteLine();
foreach (var a in alunos)
{
if (!string.IsNullOrEmpty(a.Nome))
{
Console.WriteLine($" * Aluno: {a.Nome} - Nota: {a.Nota}");
}
}
Console.WriteLine();
Console.Write("Precione qualquer tecla para voltar");
Console.ReadLine();
break;
case "3":
//TODO: Calcular Média Geral
Console.Clear();
Console.WriteLine("Detalhamento:");
Console.WriteLine();
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;
Console.WriteLine($" * Média Geral: {mediaGeral}");
Console.WriteLine();
Console.Write("Precione qualquer tecla para voltar");
Console.ReadLine();
break;
default:
throw new ArgumentOutOfRangeException();
}
opcaoUsuario = ObterOpcaoUsuario();
}
}
private static string ObterOpcaoUsuario()
{
Console.Clear();
Console.BackgroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("****************************************************");
Console.WriteLine("* Revisão DIO - ALUNOS *");
Console.WriteLine("* *");
Console.WriteLine("* 1- Inserir Novo Aluno *");
Console.WriteLine("* 2- Listar Alunos *");
Console.WriteLine("* 3- Calcular Média Geral *");
Console.WriteLine("* X- Sair *");
Console.WriteLine("* *");
Console.WriteLine("****************************************************");
Console.WriteLine();
Console.Write("Insira a opção desejada: ");
string opcaoUsuario = Console.ReadLine();
return opcaoUsuario;
}
}
}