Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

183
Visualizações
How do I manipulate a CSV file?

Create a program in Java that will read the CSV file and compute the Final Grade of the student using the computation below: Lab Exercise * 30% + Long Quiz * 30% + Alternative Assessment * 40% = Final Grade Then, display the final grade of each student.

We will be using the java.io package and so far this is what I come up with

import java.io.*;
public class ReadingFile {
public static void main (String[]args){

    try{

        File myFile = new File("Grades.csv");
        BufferedReader br = new BufferedReader(new FileReader(myFile));
        String allLines = "";

        while((allLines = br.readLine()) != null){
            String row [] = allLines.split(",");
            double finalGrade = (Double.parseDouble(row[1])*.30) + (Double.parseDouble(row[2])*.30) + (Double.parseDouble(row[3])*.40);

        }

    }
    catch(IOException err){
        System.err.println("File not found.");
        
    }
}
}

I know that there are a lot of missing code but this is all what I can do with the best of my knowledge and abilities.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Assume your content of Grades.csv is as below

35,91,24
53,63,73
13,23,33

Some tips

  1. Use try-with-resources statement to ensure that BufferedReader is closed at the end of the statement.

  2. Java uses zero-based indexing, so you should use row[0] to read the first score.

  3. Use a logger or e.printStackTrace() to help you debugging.

public static void main(String[] args) {
    try (BufferedReader br = new BufferedReader(new FileReader(new File("Grades.csv")))) {
        String allLines;
        while ((allLines = br.readLine()) != null) {
            String[] row = allLines.split(",");
            double finalGrade =
                (Double.parseDouble(row[0]) * .30) + (Double.parseDouble(row[1]) * .30) + (Double.parseDouble(row[2]) * .40);
            System.out.println(finalGrade);
        }
    } catch (IOException e) {
        System.err.println("some error message");
        e.printStackTrace();
    }
}

The output will be

47.4
64.0
24.0
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda