import 'dart:io';
void main() {
List caderneta = [];
menu(caderneta);
}
List registroAluno(List caderneta) {
String? nome;
String? nota;
List<double> notas = [];
do {
print('Digite o nome do aluno:');
nome = stdin.readLineSync();
if(nome == null || nome.isEmpty) {
print('Nome inválido');
}
} while (nome == null || nome.isEmpty);
caderneta.add(nome);
do {
print('Digite uma nota para o aluno (ou "fim" para terminar):');
nota = stdin.readLineSync();
if(nota != null && nota.isNotEmpty && nota != 'fim') {
notas.add(double.parse(nota));
}
} while (nota == null || nota.isEmpty || nota != 'fim');
caderneta.add(notas);
caderneta.add(media(notas));
return caderneta;
}
double media (List notas) {
int qtdeNotas = notas.length;
double soma = 0;
double? media;
for (double nota in notas) {
soma += nota;
}
media = soma / qtdeNotas;
return media;
}
void mostraResultado(List caderneta) {
int tamanho = caderneta.length;
for (int i = 0; i < tamanho - 2; i = i + 3) {
print('\nNome: ${caderneta[i]}');
print('Média: ${caderneta[i + 2]}');
}
}
void menu(List caderneta) {
String? entrada;
List<String> comandos = ['1', '2', '3'];
asciiArt();
print('Seja Bem-vindo ao menu');
do {
print('Digite uma operação: (1 - Registrar um aluno e notas, 2 - Visualizar média dos alunos, 3 - Sair)');
entrada = stdin.readLineSync();
if (entrada == null || entrada.isEmpty || !comandos.contains(entrada)) {
print('Entrada Inválida!');
}
} while (entrada == null || entrada.isEmpty || !comandos.contains(entrada));
switch (entrada) {
case '1':
registroAluno(caderneta);
menu(caderneta);
case '2':
mostraResultado(caderneta);
menu(caderneta);
case '3':
print('Até a próxima');
}
}
void asciiArt() {
print(" ________ ___ _______ _ _______________ ");
print(" / ___/ _ | / _ \\/ __/ _ \\/ |/ / __/_ __/ _ |");
print("/ /__/ __ |/ // / _// , _/ / _/ / / / __ |");
print("\\___/_/ |_/____/___/_/|_/_/|_/___/ /_/ /_/ |_|");
print(" ");
}