java You want to automate the grading of the multiple chioce
java
You want to automate the grading of the multiple chioce part of an exam from open file text3_Answers.txt, using the file handle inFile. Populate an array called test3Answers that contains the correct answers to test questions. You may assume one answer on each line of the input file.
Next, determine the numeber of questions student1 has gotten correct, and whether or not he/she passed the exam. A passing grade is any score 21 or greater(60%).
Scanner inFile= new Scanner (new File (\"test3_Answers.txt\"));
char [ ] student1={\'A\', \'B\', \'D\', \'D\', \'D\',\'C\', \'C\', \'A\',\'B\',\'B\',\'C\',\'A\',\'B\',\'B\',\'C\',\'A\',.....\'A\',\'A\',\'D\'); //unknown to you but
// less than 50
char[] test3Answers= new char [50];
index=0;// used to populate test3Answers
correct=0;
while (inFile.hasNext())
{
oneGrade=inFile.nextInt();
//populate test3Answersarray
Index++;
Solution
package abc;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;
public class A {
public static void main(String[] args) throws FileNotFoundException, IOException {
Scanner inFile= new Scanner (new File (\"F1.txt\"));
char [ ] student1={\'A\', \'B\', \'D\', \'D\'}; //unknown to you but
// less than 50
char[] test3Answers= new char [50];
int index=0;// used to populate test3Answers
int correct=0;
while (inFile.hasNext())
{
char oneGrade=inFile.next().charAt(0);
test3Answers[index] = oneGrade;
System.out.println(oneGrade);
index++;
}
inFile.close();
//System.out.println(index);
int passingScore = (int)(0.6 * (index-1));
System.out.println(\"Passing score -\"+passingScore);
//System.out.println(Arrays.toString(test3Answers));
for(int i=0;i<student1.length;i++){
if(student1[i] == test3Answers[i]){
correct++;
}
}
System.out.println(\"No. of correct answers - \"+correct);
if(correct >=passingScore){
System.out.println(\"Passed\");
}
else{
System.out.println(\"Fail\");
}
}
}

