Professor Nutty, who lectures encephalopathy (Med 7010), at the Cajun Medical Sc
ID: 3653577 • 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 studentsExplanation / 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(); } } } }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.