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

Assignment 6 Point Value: 20 points Due: Thursday October 19, 2017, 4:30 pm Desc

ID: 3595995 • Letter: A

Question

Assignment 6 Point Value: 20 points Due: Thursday October 19, 2017, 4:30 pm Description Write a Java program to read in a data file, calculate grade information based on that data, and then write out a new data file with the result of the requested calculations. For this project, write a Java program that: . reads in the first value in the file named grades.txt and uses that value as the total points available to determine percentage grades, reads in the next five values to determine weights (5 weights, must be converted to percent values) for students grades in the file, . weights correspond to homework (15%), projects (20%), exam 1 (20%), exam 2 (20%), and final exam (25%) reads in the rest of the values in the file as student grades (5 per student) and calculates the appropriate percentage grade based on the weighted average, Aweighted average of data x-|xi,x2,..14,] with weights w = [wi, w2, , wer», ] is computed according to the formula wa (x w+x, wxww.) where n is the length of the data. o determines the letter grade associated with that particular calculated percentage grade, writes the resulting calculation (to two decimal places only), a comma, and the letter grade to a file named finalGrades.txt. Each calculated percentage (along with corresponding letter grade) should be on its own line in this file o creates a separate report file (named finalGradesReport.txt) that writes the following: o o o o o o date batch was processed (do not hard-code, should be updated in real time), total number of students, sum of percentage grades, overall percent average (out of 100%) of all grades to two decimal places, and number of As, Bs, Cs, Ds, and Fs. Each of these final calculations should be on their own line in the report file. The program should detect and handle a FileNotFoundException by printing an error message as well as the original Exception's message. All other exceptions should be caught and handled with a generic error message. Use a finally block to indicate (output to the console) the completion of file processing.

Explanation / Answer


//create file grades.txt as mentiond and please provide path of the file according to your compiler in the the code below . Otherwise it will not write to output file


//PAssign6.java
import java.io.*;

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.ArrayList;

import java.util.Date;

import java.util.StringTokenizer;

public class PAssign6 {

static class Grades

{

int []marks;

public Grades(int[] marks) {

super();

this.marks = marks;

}

public int[] getMarks() {

return marks;

}

public void setMarks(int[] marks) {

this.marks = marks;

}

};

public static void main(String[] args) throws IOException {

int N;

int []weights = new int[5];

int studentNo=0;

double SumWa = 0;

int A=0,B=0,C=0,D=0,F=0;

ArrayList<Grades> list = new ArrayList<>();

try {

File file = new File("grades.txt");

FileReader fileReader = new FileReader(file);

File file1 = new File("finalGrades.txt");

FileWriter fileWriter1 = new FileWriter(file1);

File file2 = new File("finalGradesReports.txt");

FileWriter fileWriter2 = new FileWriter(file2);

BufferedReader bufferedReader = new BufferedReader(fileReader);

String line;

int i=0,k=0;

while ((line = bufferedReader.readLine()) != null) {

if(i==0)

{

N = Integer.parseInt(line);

}

else if(i==1)

{

StringTokenizer st = new StringTokenizer(line," ");  

while (st.hasMoreTokens()) {  

weights[k++] = Integer.parseInt(st.nextToken());

}  

}

else

{

StringTokenizer st = new StringTokenizer(line," ");  

int j=0;

int []marks = new int[5];

while (st.hasMoreTokens()) {  

marks[j++] = Integer.parseInt(st.nextToken());

}  

Grades g = new Grades(marks);

list.add(g);

double wa = 0;

for(int idx=0;i<5;i++)

{

wa = weights[idx]*g.marks[idx];

}

SumWa += wa;

if(wa > 90)

A++;

else if(wa > 80)

B++;

else if(wa > 70)

C++;

else if(wa > 60)

D++;

else

F++;

//write it to finalGrades

fileWriter1.write(line+ ", " + wa );

studentNo++;

}

i++;

}

DateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy");

Date date = new Date();

//System.out.println(dateFormat.format(date));

fileWriter2.write("Batch Processed at " + dateFormat.format(date) );

fileWriter2.write("Number of Student: "+studentNo);

fileWriter2.write("Total percentage grades: "+ SumWa);

fileWriter2.write("Average grade percentage: "+ SumWa/studentNo);

fileWriter2.write("Number of As: "+ A);

fileWriter2.write("Number of Bs: "+ B);

fileWriter2.write("Number of Cs: "+ C);

fileWriter2.write("Number of Ds: "+ D);

fileWriter2.write("Number of Fs: "+ F);

fileReader.close();

} catch (IOException e) {

e.printStackTrace();

}

}

}