Write a program to read test scores, process scores, and display a final report
ID: 3698914 • Letter: W
Question
Write a program to read test scores, process scores, and display a final report or save the report into a text file. A report is generated for a class of 4 students Note: It is not required to write a Java class with instance/static members in this project. Write in method main. A test score is an integer from 0 to 100 If an average is 90 or greater, the letter grade A is assigned Otherwise, if an average is 80 or greater, the letter grade B is assigned Otherwise, if an average is 70 or greater, the letter grade C is assigned Otherwise, the letter grade F is assigned Users can process the scores and display a report like this, save the report into a file, or quit. Test1 Test 2 Average Grade 090 082 039 089 059 080 100 092 074.5 081.0 069.5 090.5Explanation / Answer
import java.util.Scanner;
import java.io.*;
public class report {
public static void main(String[] args) throws IOException{
Scanner console=new Scanner(System.in);
int ts[]=new int[4]; //test score array
int ps[]=new int[4]; //process score array
for(int i=0;i<4;i++)
{
System.out.printf("Enter Test Score and Process Score of Student %d ::",(i+1));
ts[i]=console.nextInt();
ps[i]=console.nextInt();
}
float av[]=new float[4]; //average score array
char grade[]=new char[4]; //grades array
for(int i=0;i<4;i++)
{
av[i]=(float)(ts[i]+ps[i])/2;
if(av[i]>=90)
grade[i]='A';
else if(av[i]>=80 && av[i]<90)
grade[i]='B';
else if(av[i]>=70 && av[i]<90)
grade[i]='C';
else
grade[i]='F';
}
FileWriter fw = new FileWriter("report.txt");
PrintWriter fout = new PrintWriter(fw);
String str = String.format("Test 1 Test 2 Average Grade ");
String str2 = String.format(" ------ ------ ------ ------ ");
fout.println(str);
fout.println(str2);
for(int i=0;i<4;i++)
{
String s=String.format("%d %d %f %c ",ts[i],ps[i],av[i],grade[i]);
fout.println(s);
}
fout.close();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.