Write a program which reads student names, social security numbers, and test sco
ID: 3534897 • Letter: W
Question
Write a program which reads student names, social security numbers, and test scores from an input file named infile.
The program then computes a weighted average, finds the appropriate letter grade, and displays the formatted output
specified below to the screen. The information reading should be controlled by a while Loop. Termination should
occur after the input file is empty. If a student has a grade of "A" (0.90 or more) and each score is at least 0.85, then
a mark of distinction should be entered in the output. The range will be computed by the difference of the highest
and lowest grade for a student.
Readings: Building Blocks: Types, Classes, and Objects, While loop, File Stream I/O
Explanation / Answer
import java.lang.*;
import java.util.*;
import java.io.*;
class StudentGrade
{
public static int ReadInteger()
{
try
{
InputStreamReader input = new InputStreamReader(System.in);
BufferedReader reader = new BufferedReader(input);
return Integer.parseInt(reader.readLine());
}
catch (Exception e)
{
e.printStackTrace();
return 0;
}
}
public static void main(String[] args)
{
System.out.println("Program for simple student grading logic.");
int MAX_STUDENTS = 10;
int [] arrMark = new int[MAX_STUDENTS];
String grade = "";
for (int i = 0; i < MAX_STUDENTS; i++)
{
System.out.format("Enter %d Student Mark: ", i + 1);
arrMark[i] = ReadInteger();
}
System.out.print(" No Mark Grade ");
for (int i = 0; i < MAX_STUDENTS; i++)
{
if(arrMark[i] > 100)
grade = "Error";
else if(arrMark[i] > 90)
grade = "A+";
else if(arrMark[i] > 70)
grade = "B+";
else if(arrMark[i] > 50)
grade = "C+";
else if(arrMark[i] > 30)
grade = "C";
else
grade = "F";
System.out.format("%d %d %s ", i + 1, arrMark[i], grade);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.