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

Your program should open an ASCII file prog10in.txt for input, sort the data and

ID: 3693401 • Letter: Y

Question

Your program should open an ASCII file prog10in.txt for input, sort the data and write the data to a file prog10out.txt. The two file names must be passed to the program. You should use the “employeeList” example discussed in class as a model for this assignment.

The data contained in the input file consists of final grade information of student. Each student record is stored in a line with blank(s) separating the fields. There are six fields in the record (an ID, Last Name, First Name, and 3 Grades). ID is an integer number and grades are double. See a sample file below.

Your program should :Open the input FIle, read all record into StudentList class,Sort the students in decrease order based on their gradeWrite the sorted records out to a file and to your monitor (the good old cout).

Add a column for a letter grade where

90 and above is an A

80 and above is a B

70 and above is a C

60 and above is a D

Below that is an F

Input: You will be reading from the data file prog10in.txt in this assignment. No interactive input. A sample file will be provided for you to test the program. Keep in mind this is just a sample file.

Output You will be reading from the data file prog10out.txt in this assignment.
10033 Jaspal Subhlok 100.00 96.00 98.00 98.00 A

Requirement:

You must use a class definition described above and its associated member functions. You must use program arguments (argv). This will be your first use of the argv.
The demo program is about 110 lines.

Explanation / Answer

import java.io.*; class Test { public static void main(String[] argv) { processGrades(argv[1], argv[2]); } public static void processGrades(String input_name, String csv_name) { BufferedReader br = null; StringBuffer b = new StringBuffer(); File file2 = new File(csv_name); try { if (!file2.exists()) { file2.createNewFile(); } FileWriter fw2 = new FileWriter(file2.getAbsoluteFile()); BufferedWriter bw2 = new BufferedWriter(fw2); String line; br = new BufferedReader(new FileReader(input_name)); while ((line = br.readLine()) != null) { String[] s = line.split(","); int id = Integer.parseInt(s[0]); String fname = s[1]; String lname = s[2]; double exam_score1 = Double.parseDouble(s[3]); double exam_score2 = Double.parseDouble(s[4]); double exam_score3 = Double.parseDouble(s[5]); double avg = (exam_score1+exam_score2+exam_score3)/3; String grade = getGrade(avg); bw2.write(id+" "+fname+" "+lname+" "+exam_score1+" "+exam_score2+" "+exam_score3+" "+avg+" "+","+grade); } } catch (IOException e) { e.printStackTrace(); } finally { try { if (br != null)br.close(); } catch (IOException ex) { ex.printStackTrace(); } } } public static String getGrade(double m){ String g; if(m>90) g = "A"; else if(m>80) g = "B"; else if(m>70) g = "C"; else if(m>60) g = "D"; else g = "F"; return g; } }