Use Jave programming Write in Jave a grading program that En
Use Jave programming
Write in Jave a grading program that:
Enter a student name
 Generates 5 scores between 50 and 100
 Sums the scores
 Computes the average of the scores
 Converts the scores into a letter grade - A, B, C, D, F where F is below 60%
 convert using: if else if else and switch
 Print out a name for the student, the average score, and the letter grade
You will be graded on the following program features:
 Correct use of indentation.
 Correct use of white space
 Readability
 Verification and validation
Use Jave programming
Solution
import static java.lang.System.out;
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
public class LetterGrader {
private static FileReader fr;
private static PrintWriter pw;
private static BufferedReader br;
private static String line;
public static void main(String[] args) throws IOException {
int numGrades = 0, Length = 0;
int[] gradesArray;
String FileName;
FileReader in = new FileReader(input_data.txt);
try{
LetterGrader letterGrader = new LetterGrader(args[0], args[1]);
fr = new FileReader(args[0]);
pw = new PrintWriter(args[1]);
br = new BufferedReader(fr);
String [] s = line.split(\", \");
String sLine = br.readLine()
numGrades = Integer.parseInt(s);
gradesArray = new int[numGrades];
for(int i=0; i<numGrades; i++)
sLine = br.readLine();
int validGrades = Integer.parseInt(s);
if (validGrades >= 0 && validGrades <= 100)
{
gradesArray[i] = validGrades;
Length++;
calcLetterGrades(validGrades);
}
}
System.out.println(\"Average: \" + max(gradesArray, Length));
System.out.println(\"Minimum: \" + min(gradesArray, Length));
System.out.println(\"Maximum: \" + max(gradesArray, Length));
in.close();
}
catch (Exception e)
{
System.out.println(\"Error: \" + e.getMessage());
}
}
public InputStream openFile(String fileName) throws IOException {
textPrintStream = new PrintWriter(new FileOutputStream(\"output_data.txt\"));
if(textPrintStream == null)
throw new IOException(\"File not found: \" + fileName);
return textPrintWriter.openStream();
}
public static char calcLetterGrades(int grades) { // s[1] is quiz one, s[2] is quiz 2, s[3] is quiz 3, s[4] is quiz 4, s[5] is midterm 1, s[6] is midterm 2, s[7] is the final grade
char result;
double grade = s[1] * .10 + s[2] * .10 + s[3] * .10 + s[4] * .10 + s[5] * .20 + s[6] * .15 + s[7] * .25;
if(grade >= 90) {
result = \'A\';
} else if(grade >= 80 && <= 89){
result = \'B\';
} else if(grade >= 70 && <= 79){
result = \'C\';
} else if(grade >= 60 && <= 69){
result = \'D\';
} else {
result = \'F\';
}
return result;
}
public static int min(int[] a, int Length)
{
int min = 100;
for(int i=0; i<Length; i++)
{
if(a[i] < min)
min = a[i];
}
return min;
}
public static int max(int[] a, int Length)
{
int max = 0;
for(int i=0; i<Length; i++)
{
if(a[i] > max)
max = a[i];
}
return max;
}
public static double Avg(int[] a, int Length)
{
double Avg = 0;
int total = 0;
for(int i = 0; i < Length; i++)
{
total += a[i];
}
Avg = total / Length;
return Avg;
}
//public static void displayAverages() {
//out.println(\"Letter grade has been calculated for students listed in the input file and outputted in the output file.\");
//out.println(\"\\t\\tQuiz1\\tQuiz2\\tQuiz3\\tQuiz4\\tMid1\\tMid2\\tFinal\");
//out.printf(\"\ Average:\\t%5.2f\\t%5.2f\\t%5.2f\\t%5.2f\\t%5.2f\\t%5.2f\\t%5.2f\", s[1].avg, s[2].avg, s[3].avg, s[4].avg, s[5].avg, s[6].avg, s[7].avg);
//out.printf(\"\ Minimum:\\t%5.2f\\t%5.2f\\t%5.2f\\t%5.2f\\t%5.2f\\t%5.2f\\t%5.2f\", s[1].min, s[2].min, s[3].min, s[4].min, s[5].min, s[6].min, s[7].min);
//out.printf(\"\ Maximum:\\t%5.2f\\t%5.2f\\t%5.2f\\t%5.2f\\t%5.2f\\t%5.2f\\t%5.2f\", s[1].max, s[2].max, s[3].max, s[4].max, s[5].max, s[6].max, s[7].max);
//}
public static void doCleanup() {
try{
fr.close();
br.close();
pw.close();
}catch(Exception e){
e.printStackTrace();
}
}





