Your assignment is to produce a grade report for five students. Using a file to
ID: 3845367 • Letter: Y
Question
Your assignment is to produce a grade report for five students. Using a file to store the data and retrieve the data for the program. Your program will send the report to an external file as well as the screen. The data will include a five digit student ID, and three test scores. You will then calculate the average for each student, determine their letter grade and student status. For a grade of F the status will be Fail, for a grade of D the status will be Poor for a grade above of C the status will be Satisfactory, a grade of B will be good and an A will be Excellent. Your report will also give me the class average for the five students. I should be able to put any five students with any three grades for each student into your report.
Explanation / Answer
Solution:
classReport.java
package classreport;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class ClassReport {
public static void main(String[] args) throws FileNotFoundException, IOException {
Student stu[]=new Student[10];
Scanner s1 = new Scanner(new File("inp.txt"));
int i=0;
while (s1.hasNext()){
stu[i]=new Student(s1.nextInt(),s1.nextDouble(),s1.nextDouble(),s1.nextDouble());
i++;
}
System.out.println(" Class Report ");
System.out.println("Student Number Average Grade Status");
for(int k=0;k<i;k++)
{
System.out.println(stu[k].studentID+" "+stu[k].average+" "+stu[k].grade+" "+stu[k].status);
}
File f=new File("out.txt");
FileWriter fwr = new FileWriter(f);
fwr .write(" Class Report ");
fwr.write(" ");
fwr .write("Student Number Average Grade Status ");
for(int k=0;k<i;k++)
{
fwr.write(stu[k].studentID+" "+stu[k].average+" "+stu[k].grade+" "+stu[k].status+" ");
}
fwr.close();
}
}
Student.java
package classreport;
public class Student {
int studentID;
double score1;
double score2;
double score3;
double average;
char grade;
String status;
public Student(int id, double sc1,double sc2,double sc3)
{
studentID=id;
score1=sc1;
score2=sc2;
score3=sc3;
average=(score1+score2+score3)/3;
if(average>90 && average<=100)
{
grade='A';
status="Excellent";
}
else if(average>80 && average<=90)
{
grade='B';
status="Good";
}
else if(average>70 && average<=80)
{
grade='C';
status="Satisfactory";
}
else if(average>60 && average<=70)
{
grade='D';
status="Poor";
}
else
{
grade='F';
status="Fail";
}
}
}
Output:
run:
Class Report
Student Number Average Grade Status
12345 20.0 F Fail
23456 68.33333333333333 D Poor
34567 68.33333333333333 D Poor
45678 45.666666666666664 F Fail
56789 72.66666666666667 C Satisfactory
BUILD SUCCESSFUL (total time: 0 seconds)
inp.txt
12345 20 20 20
23456 60 89 56
34567 65 70 70
45678 56 56 25
56789 80 84 54
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.