0
respostas

Exercício Final - Aprendendo DART.

import 'dart:io';

void main() {
  List<String> nomes = [];
  List<List<double>> notas = [];
  
  menu(nomes, notas);

   double resultadoMedia = media(notas);
   print('A média das notas é: $resultadoMedia');
}

List<String> registrar(List<String> nomes, List<List<double>> notas) {
  print('Digite o nome do aluno: ');
  String nomeDigitado = stdin.readLineSync()!;
  nomes.add(nomeDigitado);
  
  List<double> notasAluno = [];
  computarNotas(notasAluno);
  notas.add(notasAluno);

  return nomes;
}

void computarNotas(List<double> notas) {
  print('Digite uma nota para o aluno (ou "fim" para terminar):');
  String opcao = stdin.readLineSync()!;

  if (opcao != "fim") {
    double nota = double.parse(opcao);
    notas.add(nota);
    computarNotas(notas);   
  }
}

double media(List<List<double>> notas) {
  double total = 0;
  int quantidadeNotas = 0;

  for (List<double> notasAluno in notas) {
    for (double nota in notasAluno) {
      total += nota;
      quantidadeNotas++;
    }
  }

  return quantidadeNotas > 0 ? total / quantidadeNotas : 0; // Evita divisão por zero
}

void exibirHistorico(List<String> nomes, List<List<double>>notas){
  for(int i = 0; i < nomes.length; i++){
   
    print('');
    print('Nome: ${nomes[i]}');
    print('Notas: ${notas[i]}');
  }
}

void menu(List<String> nomes, List<List<double>>notas){
  print("");
  print ("  __  __ _       _                             _            ");
  print (" |  \/  (_)     | |                           | |           ");
  print (" | \  / |_ _ __ | |__   __ _ ___   _ __   ___ | |_ __ _ ___ ");
  print (" | |\/| | | '_ \| '_ \ / _\` / __| | '_ \ / _ \| __/ _\` / __|");
  print (" | |  | | | | | | | | | (_| \__ \ | | | | (_) | || (_| \__ \ ");
  print (" |_|  |_|_|_| |_|_| |_|\__,_|___/ |_| |_|\___/ \__\__,_|___/");
  print ("                                                            ");
  print ("                                                            ");
  print("");
  print('Selecione uma opção: 1 - Registrar aluno | 2 - Listar alunos | 3 - Sair');
  String opcaoEscolhida = stdin.readLineSync()!;

  switch(opcaoEscolhida){
    case "1":
    registrar(nomes, notas);
    menu(nomes, notas);
    case "2":
    exibirHistorico(nomes, notas);
    menu(nomes, notas);
    case "3":
    print("Saindo...");
  }
}