import 'dart:io';
class Aluno{
String nome;
List<double> notas;
Aluno(this.nome, this.notas);
double calcularMedia(){
double soma = notas.reduce((a, b) => a + b);
return soma / notas.length;
}
}
void main(){
cabecalho();
List<Aluno> alunos = [];
menu(alunos);
}
Aluno registrarAluno(){
String? nome;
do {
print("Digite o nome do aluno:");
nome = stdin.readLineSync();
} while (nome == null || nome.isEmpty);
String? entrada;
List<double> notas = [];
while (true){
print("");
print("Digite a nota do aluno ou fim para sair");
entrada = stdin.readLineSync();
if (entrada == "fim"){
break;
}
if (entrada == null || entrada == ""){
print("Entrada invalida");
continue;
}
double? numero = double.tryParse(entrada!);
if(numero == null) {
print("Entrada invalida");
continue;
}
notas.add(numero!);
}
return Aluno(nome, notas);
}
void listaAlunosMedias(List<Aluno> alunos){
for (var aluno in alunos){
print("${aluno.nome} teve média final de ${aluno.calcularMedia()}");
}
}
String comandosMenu(){
print("");
print("Escolha um comando:\n 1 - Registrar um aluno e sua nota,\n 2 - Ver a lista de todos alunos registrados e suas médias escolares,\n 3 - Sair do programa.");
print("");
List<String> comandos = <String>["1", "2", "3"];
String? comando = stdin.readLineSync();
if(comando == null || !comandos.contains(comando)){
print("Comando inválido");
return comandosMenu();
}
return comando;
}
void menu(List<Aluno> alunos){
String comando = comandosMenu();
print("");
switch (comando){
case "1":
Aluno novoAluno = registrarAluno();
alunos.add(novoAluno);
menu(alunos);
case "2":
listaAlunosMedias(alunos);
menu(alunos);
case "3":
print("Programa encerrado.");
print("");
break;
}
}
void cabecalho(){
print(" ┏┓• ┓ ");
print(" ┗┓┓┏╋┏┓┏┳┓┏┓ ┏┫┏┓ ");
print("┏┓ ┗┛┗┛┗┗┓┛┗┗┗┻ ┗┻┗ ┏┓ ┓ ");
print("┣┫┏┏┓┏┳┓┏┓┏┓┏┓┣┓┏┓┏┳┓┏┓┏┓╋┏┓ ┣ ┏┏┏┓┃┏┓┏┓");
print("┛┗┗┗┛┛┗┗┣┛┗┻┛┗┛┗┗┻┛┗┗┗ ┛┗┗┗┛ ┗┛┛┗┗┛┗┗┻┛ ");
print(" ┛ ");
}