Buscar

Leitura e Cálculo de Notas

Prévia do material em texto

ATENÇÃO: Toda atividade deverá ser feita com fonte Arial, tamanho 11, espaço de 1,5 entre as linhas e 
alinhamento justificado entre as margens. 
 
 
import java.io.BufferedReader; 
import java.io.FileReader; 
import java.io.IOException; 
import java.util.ArrayList; 
 
public class Main { 
 public static void main(String[] args) { 
 ArrayList<Double> notas = new ArrayList<>(); 
 double somaNotas = 0.0; 
 
 try (BufferedReader br = new BufferedReader(new FileReader("alunos.txt"))) { 
 String linha; 
 while ((linha = br.readLine()) != null) { 
 String[] partes = linha.split(";"); 
 if (partes.length == 3) { 
 double nota = Double.parseDouble(partes[2]); 
 notas.add(nota); 
 somaNotas += nota; 
 } 
 } 
 } catch (IOException e) { 
CURSO: Análise e desenvolvimento de sistemas 
POLO DE APOIO PRESENCIAL: Higienópolis 
SEMESTRE: 3 
COMPONENTE CURRICULAR / TEMA: Estrutura de dados 
NOME COMPLETO DO ALUNO: Flávio Morales 
TIA: 22504907 
NOME DO PROFESSOR: Thiago Donizetti dos Santos 
 
ATENÇÃO: Toda atividade deverá ser feita com fonte Arial, tamanho 11, espaço de 1,5 entre as linhas e 
alinhamento justificado entre as margens. 
 
 e.printStackTrace(); 
 } 
 
 if (notas.size() > 0) { 
 double media = somaNotas / notas.size(); 
 System.out.println("Media das notas: " + media); 
 System.out.println("Notas maiores ou iguais à média:"); 
 for (Double nota : notas) { 
 if (nota >= media) { 
 System.out.println("Nota maior que a média => " + nota); 
 } 
 } 
 System.out.println("Fim do programa."); 
 } else { 
 System.out.println("Nenhuma nota encontrada no arquivo."); 
 } 
 } 
}

Continue navegando

Outros materiais