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

File hw6_task1.java contains an incomplete program. The goal of the program is c

ID: 3692553 • Letter: F

Question

File hw6_task1.java contains an incomplete program. The goal of the program is compute the semester grade for each student in a class, based on exam and homework scores for that student. The grades are stored in a CSV file, following this format:

The top row contains column names.

After that, each row contains data for a specific student.

Column 0 contains first names.

Column 1 contains last names.

Columns 2, 3, 4 contain exam scores.

Columns 5 to 11 contain homework scores.

An example of such a CSV file is data1.txt.

Complete that program, by writing methods to read the data from the file (feel free to use the methods posted in class) and process it. In order to process the data, define a processGrades function, that satisfies the following specs:

The function takes three arguments, called input_name, csv_name, pretty_name (the filename includes the extension).

Argument input_name is the name of the CSV file containing the grade data that your code needs to process, e.g. "data1.txt".

Argument csv_name is the name of an output CSV file, where your code will save the grade data that you have computed. This output CSV file will have a top row with column names, and then one row per student. The file will have five columns:

Column 0 contains the name of the student (concatenation of first name and last name, separated by space).

Column 1 contains the average exam score for that student.

Column 2 contains the average homework score for that student.

Column 3 contains the smallest value between the exam average score and the homework average score for that student.

Column 4 contains the letter grade, by converting the value at column 3, using standard threshold (90 and above is A, 80 to 90 is B, 70 to 80 is C, 60 to 70 is D, below 60 is F).

An example output CSV file following these specifications is csv1.txt.

Argument pretty_name is the name of an output text file, where your code will print out the grade data that you have computed, in a nice, tabular format that is easy for humans to read. This output text file will have a top row with column names, and then one row per student. The file will have the same five columns as the output CSV file described above. However, each column will be aligned. To obtain aligned columns, my solution uses this code to print each row:

An example output CSV file following these specifications is pretty1.txt.

For example, suppose that:

You use this data1.txt as your input file.

You enter "csv1.txt" for the CSV output file, and "pretty1.txt" for the pretty-print file.

Then, your code should produce files that look EXACTLY like files csv1.txt and pretty1.txt obtained using my solution. Use the same format, column names and spacing as you see in these example output files.

IMPORTANT: you are only allowed to modify the provided code by writing the requested functions, and possibly additional auxiliary functions (you are encouraged to come up with several such auxiliary functions in this task). You are NOT allowed to modify in any way the main function, or any other function that is already provided.

Explanation / Answer

import java.io.*; import java.util.Scanner; /** * This program ... * @author */ class Test { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.printf("Please enter the name of the input file: "); String inputName = in.next(); System.out.printf("Please enter the name of the output CSV file: "); String csvName = in.next(); System.out.printf("Please enter the name of the output pretty-print file: "); String prettyName = in.next(); processGrades(inputName, csvName, prettyName); System.out.printf(" Exiting... "); } public static void processGrades(String input_name, String csv_name, String pretty_name) { BufferedReader br = null; StringBuffer b = new StringBuffer(); File file2 = new File(csv_name); try { // if file doesnt exists, then create it if (!file2.exists()) { file2.createNewFile(); } PrintWriter pw1 = new PrintWriter(new FileWriter(pretty_name, true)); 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(","); String name = s[0]; double exam_score = (Double.parseDouble(s[1])+ Double.parseDouble(s[2])+ Double.parseDouble(s[3]))/3; double hw_score = (Double.parseDouble(s[4])+ Double.parseDouble(s[5])+ Double.parseDouble(s[6]))/3; double min_score = exam_score>hw_score? hw_score : exam_score; String grade = getGrade(min_score); pw1.printf("%20s: %10.2f, %8.2f, %9.2f, %s ", name, exam_score, hw_score, min_score, grade); bw2.write(name+","+exam_score+","+hw_score+","+min_score+","+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; } }

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