
Write a JAVA program to auto-grade exams. For a class of N students, your program should read letter answers (A, B, C, D) for each student. Assume there are 5 questions in the test. Your program should finally print the grade percentage (out of 100%) of each student, and also the class average. Define the exam answer key as Final Array in your program.

import java.io.*;
public class Test1{
public static void main(String args[]){
String ans1="a",ans2="a",ans3="a",ans4="a",ans5="a";
double totPercentage = 0.00;
double avgPercentage = 0.00;
System.out.println("Enter No. Of Students");
try{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String s = br.readLine();
int n = Integer.parseInt(s);
for(int i=1;i<=n;i++){
int count =0;
System.out.println("Give the answers for student "+i);
System.out.println("First Question select choice : A B C D");
String ansr1 = br.readLine();
if(ansr1.equalsIgnoreCase(ans1))
count=count+1;
System.out.println("Second Question select choice : A B C D");
String ansr2 = br.readLine();
if(ansr2.equalsIgnoreCase(ans2))
count=count+1;
System.out.println("Third Question select choice : A B C D");
String ansr3 = br.readLine();
if(ansr3.equalsIgnoreCase(ans3))
count=count+1;
System.out.println("Fourth Question select choice : A B C D");
String ansr4 = br.readLine();
if(ansr4.equalsIgnoreCase(ans4))
count=count+1;
System.out.println("Fifth Question select choice : A B C D");
String ansr5 = br.readLine();
if(ansr5.equalsIgnoreCase(ans5))
count=count+1;
double percentage = (count/5.0)*100;
System.out.println("Percentage : "+percentage+"%");
totPercentage =totPercentage+percentage;
}
avgPercentage= totPercentage/n;
System.out.println("Class Avg : "+avgPercentage+"%");
}
catch(Exception e){
e.printStackTrace();
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.