Answered step by step
Verified Expert Solution
Question
1 Approved Answer
import java.io . * ; import java.util.Scanner; public class StudentGradeReport { public static void main ( String [ ] args ) { Scanner scanner =
import java.io;
import java.util.Scanner;
public class StudentGradeReport
public static void mainString args
Scanner scanner new ScannerSystemin;
Step : Read the file name of the tsv file from the user
System.out.printEnter the name of the TSV file: ;
String tsvFileName scanner.nextLine;
try
Step : Open the tsv file and read student information
BufferedReader tsvReader new BufferedReadernew FileReadertsvFileName;
FileWriter reportFile new FileWriterreporttxt;
BufferedWriter reportWriter new BufferedWriterreportFile;
double totalMidterm;
double totalMidterm;
double totalFinal ;
int studentCount ;
String line;
while line tsvReader.readLine null
String data line.splitt;
if datalength
String lastName data;
String firstName data;
double midterm Double.parseDoubledata;
double midterm Double.parseDoubledata;
double finalScore Double.parseDoubledata;
Calculate the average exam score
double averageScore midterm midterm finalScore;
Assign a letter grade
String letterGrade assignLetterGradeaverageScore;
Output student information to report.txt
reportWriter.writelastName t firstName t midtermt midtermt finalScore t letterGrade;
reportWriter.newLine;
Update totals for average exam scores
totalMidterm midterm;
totalMidterm midterm;
totalFinal finalScore;
studentCount;
tsvReader.close;
reportWriter.close;
Calculate and output the average of each exam with two digits after the decimal point
double avgMidterm totalMidterm studentCount;
double avgMidterm totalMidterm studentCount;
double avgFinal totalFinal studentCount;
FileWriter avgFile new FileWriterreporttxt true;
BufferedWriter avgWriter new BufferedWriteravgFile;
avgWriter.newLine;
avgWriter.writeAverage Exam Scores: ;
avgWriter.writeStringformatMidterm: ftMidterm: ftFinal: f avgMidterm avgMidterm avgFinal;
avgWriter.close;
System.out.printlnReport generated successfully!";
catch IOException e
System.err.printlnAn error occurred while processing the file: egetMessage;
private static String assignLetterGradedouble averageScore
if averageScore
return A;
else if averageScore
return B;
else if averageScore
return C;
else if averageScore
return D;
else
return F;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started