Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Professor Nutty, who lectures encephalopathy (Med 7010), at the Cajun Medical Sc

ID: 3632018 • Letter: P

Question

Professor Nutty, who lectures encephalopathy (Med 7010), at the Cajun
Medical School gave three equally weighted exams to his students during the
course (preliminary, middle, and terminal exams). The students’ scores are
kept in a text file. Each row of the text file consists of the student’s ID#
followed by his/her test scores. At the end of the course, Professor Nutty
needs a C++ program that computes average test scores and letter grades
for each student. Professor Nutty wants a report consisting of each student’s
best two scores, the average of the best two scores, and the letter grade
corresponding to the average. In other words, Professor Nutty will drop the
lowest exam score. The exam scores are not sorted in the input file.
Your program will prompt the user for the name of the input file and
read the data from it. Your program will generate a report showing the
ID#, the best two scores, the average of the best two scores and letter grade
corresponding to the average. The report will be stored in an output text
file whose name the user will be prompted to enter.

Your program should prompt the user for the name of the input and out-put files. Be sure to perform error-check on both files to determine whetherthe input file is successfully opened and whether the output file is successfullycreated. Your program should then generate a report following the formatbelow. Ensure that numeric values in the report are formatted so that theyhave the same number of decimal places as shown in the sample output be-low. Once the data from the input file have been processed, close the file.Also, close the output file before the program terminates.

For a sample input file, ence7010f11.grd, with the data below:

2008-EN-001 95 80 100

2009-NE-095   60 98 97.5

2011-PA-158 80 70 50

A typical program interaction would be:

Enter the name of the data file> ence7010f11.grd

Enter the name of the output file> ence7010f11.rpt

Here is the contents of the sample output file (ence7010f11.rpt):

Encephalopathy (Med-7010)

Final Course Report

Fall 2011

================================================

ID# Score Average Grade

2008-EN-001 95.00% 97.500% A

2009-NE-095 97.50% 97.750% A

2011-PA-158 70.00% 75.000% C

------------------------------------------------

*** END OF REPORT ***

================================================

I will rate lifesaver for any help that can be given! Thank you for looking!

Explanation / Answer

package filegrades; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class FileGrades { public static void main(String[] args) throws IOException { InputStreamReader inp = new InputStreamReader(System.in); BufferedReader input = new BufferedReader(inp); System.out.println("Enter the name of the data file> "); String strInputFile = "c:\" +input.readLine(); System.out.println("Enter the name of the output file> "); String strOutputFile = "c:\" + input.readLine(); StringBuilder sbOutput =new StringBuilder(); sbOutput.append(" Encephalopathy (Med-7010)").append(System.getProperty("line.separator")) .append(" Final Course Report").append(System.getProperty("line.separator")) .append(" Fall 2011").append(System.getProperty("line.separator")) .append("================================================ ").append(System.getProperty("line.separator")) .append("ID# Score Average Grade") .append(System.getProperty("line.separator")); BufferedWriter outputData = null; BufferedReader inputData=null; try { inputData = new BufferedReader(new FileReader(strInputFile)); if(inputData != null) { String line = null; while (( line = inputData.readLine()) != null) { String[] str = line.split(" "); String stuName = ""; double[] scores; if(str!=null && str.length > 1) { scores = new double[str.length-1]; stuName = str[0]; for(int i=1;i= 90) { Grade = "A"; } else if(AvgScore >= 80 && AvgScore < 90) { Grade = "B"; } else if(AvgScore >= 70 && AvgScore < 80) { Grade = "C"; } else { Grade = "D"; } sbOutput.append(stuName).append(" ") .append(String.format("%3.2f%s", scores[scores.length-1],"%")).append(" ") .append(String.format("%3.2f%s", scores[scores.length-2],"%")).append(" ") .append(String.format("%3.3f%s", AvgScore,"%")).append(" ") .append(Grade).append(System.getProperty("line.separator")); } } } else { System.out.println("Unable to open input file : " + input); System.exit(0); } } catch(Exception exp) { System.out.println("Unable to read/process input file : " + input); System.exit(0); } finally { sbOutput.append(" -------------------------------- ").append(System.getProperty("line.separator")) .append(" *** END OF REPORT ***").append(System.getProperty("line.separator")) .append("================================================ "); if(inputData != null) { inputData.close(); } } try { outputData= new BufferedWriter(new FileWriter(strOutputFile)); outputData.write( sbOutput.toString() ); } catch(Exception exp) { System.out.println("Unable to open output file : " + input); System.exit(0); } finally { if(outputData != null) { outputData.close(); } } } } Note: I got confused with output format. Whether we need to display one of the best 2 scores or both scores we have to display. In this program i have displayed both. One more thing conditions for Grades. i have assumed that A grade(>=90%), B grade(>=80% and < 90%), C grade(>= 70% and < 80%), else D grade.
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote