computer science
import java.io.*; import java.util.*; public class Project33 { public static void main(String[] args) throws FileNotFoundException { String QuizAnswers = " "; double numCorrect = 0; String Answers = " "; String StudentName = " "; int index; int numAnswers = 0; double grade = 0.0; double numWrong = 0.0; Scanner cscan = new Scanner(System.in); System.out.println("Please enter the student file name: "); String filename = " "; filename = cscan.nextLine(); // check for existence of file File file1 = new File(filename); if (!file1.exists()) { System.out.println("File " + filename + " does not exist."); } System.out.println("Please enter the Quiz Key file name: "); String filename2 = " "; filename2 = cscan.nextLine(); // check for existence of file File file2 = new File(filename2); if (!file2.exists()) { System.out.println("File" + filename2 + " does not exist."); } System.out.println("\n\n"); System.out.println("Name" + " " + " Correct" + " " + " Wrong" + " " + " Grade"); System.out.println("----" + " " + " -------" + " " + " -----" + " " + " -----"); Scanner ifile2 = new Scanner(file2); // Open the Quiz Key file while(ifile2.hasNext()) { QuizAnswers = ifile2.next(); Scanner ifile1 = new Scanner(file1); // Open the Student Quiz file with answers while(ifile1.hasNext())//Scan each line in student file and collect data { Answers = ifile1.next(); numAnswers = Answers.length(); if(numAnswers == 0) // Checks to see if student file doesn't have any test answers { StudentName = StudentName + " Input Error! No Answer In Student Record On This Line."; numCorrect = 0.0; numWrong = 0.0; grade = 0.0; } StudentName = ifile1.nextLine(); // Collect student name if(!(StudentName.length() > 0) || StudentName.charAt(1) == ' ') // Check for Student Name input error { StudentName = StudentName + " Input Error! No Student Name On This Line."; } int numQuizAns = QuizAnswers.length(); if(numAnswers > numQuizAns || numAnswers < numQuizAns) // Check to see if number of student answers matches number of Quiz answers { StudentName = StudentName + " Input Error! Invalid Number of Answers On This Line."; } else { for(index = 0; index < numAnswers; index++) // Scan each char in student answers and compare to quiz answers { if(Answers.charAt(index) == QuizAnswers.charAt(index)) // Add to numCorrect if both characters are equal { numCorrect++; } Else // also test for lowercase letters in Answer string { if(Answers.charAt(index)=='f' && QuizAnswers.charAt(index)=='F') { numCorrect++; } if(Answers.charAt(index)=='t' && QuizAnswers.charAt(index)=='T') { numCorrect++; } } } } numWrong = numQuizAns - numCorrect; // Calculate the number of wrong answers and output results grade = (numCorrect/numQuizAns) * 100; System.out.println(StudentName + " " + " " + numCorrect + " " + numWrong + " " + grade + "%"); numCorrect = 0; } ifile1.close(); } ifile2.close(); } }