import java.io.*; import java.util.Scanner; class ExamAnalysis { public static void main (String [] args) throws FileNotFoundException { System.out.println ("I hope you are ready to begin..."); Scanner keyboard = new Scanner(System.in); System.out.println(); System.out.println("Please type the correct answers to the exam questions, one right after the other: "); String answers = keyboard.nextLine(); System.out.println("Where is the name of the file containing each student's responses to the 10 questions? "); String responses = keyboard.nextLine(); Scanner read = new Scanner(new File(responses)); while (read.hasNextLine()) { int i = 0; int numberOfStudents = 9; while (i < numberOfStudents && read.hasNextLine()) { responses = read.nextLine(); i++; System.out.println("Student # " + i + "'s"+ " responses: " + responses.substring(0,10)); } System.out.println("We have reached 'end of file'!"); System.out.println(); System.out.println("Thank you for the data on "+ numberOfStudents +" students. Here's the analysis: "); resultsByStudents(responses, answers); analysis(responses, answers); } } public static void resultsByStudents(String responses, String answers) { System.out.println ("Student # Correct Incorrect Blank"); System.out.println ("~~~~~~~~~ ~~~~~~~ ~~~~~~~~~ ~~~~~"); int student = 0; int correct = 0; int incorrect = 0; int blank = 0; for (int i = 0; i < 9; i++) { for (int j = 0; j < responses.length(); j++) { if ((responses.charAt(j)) == answers.charAt(j)) correct++; else if ((responses.charAt(j)) != answers.charAt(j)) incorrect++; else blank++; } System.out.println(student + " " + correct + " " + incorrect + " " + blank); student++; } } public static void analysis(String responses, String answers) { System.out.println("QUESTION ANALYSIS (* marks the correct response)"); System.out.println("~~~~~~~~~~~~~~~~~"); double A = 0.0; double B = 0.0; double C = 0.0; double D = 0.0; double E = 0.0; double X = 0.0; for (int i = 1; i < 10; i++) { for (int j = 0; j < responses.length(); j++) { int chooseA = 0; int chooseB = 0; int chooseC = 0; int chooseD = 0; int chooseE = 0; int chooseBlank = 0; A = chooseA/9; B = chooseB/9; C = chooseC/9; D = chooseD/9; E = chooseE/9; X = chooseBlank/9; String a = "A"; String b = "B"; String c = "C"; String d = "D"; String e = "E"; String blank = "Blank"; if (responses.charAt(j) == A) chooseA++; else if (responses.charAt(j) == B) chooseB++; else if (responses.charAt(j) == C) chooseC++; else if (responses.charAt(j) == D) chooseD++; else if (responses.charAt(j) == E) chooseE++; else chooseBlank++; System.out.println("Question #" + i); if (answers.charAt(i) == 'A') a = "A*"; else if (answers.charAt(i) == 'B') b = "B*"; else if (answers.charAt(i) == 'C') c = "C*"; else if (answers.charAt(i) == 'D') d = "D*"; else if (answers.charAt(i) == 'E') e = "E*"; System.out.println(a + " " + b + " " + c + " " + d + " " + e + " " + blank); System.out.println (chooseA + " " + chooseB + " " + chooseC + " " + chooseD + " " + chooseE + " " + chooseBlank ); System.out.println (A + " " + B + " " + C + " " + D + " " + E + " " + X); } } } }