Package Com.iotest;import Java.io.bufferedreader;import Java.io.bufferedwriter;import java.io.File;import Java.io.filereader;import java.io.filewriter;import Java.io.ioexception;import Java.util.Scanner;public class Exem_ Scode2 {@SuppressWarnings ("resource") public static void main (string[] Args) {Scanner input = new Scanner (system.in); File F1 = new ("f:\\exam02");//create The files object of the operation directory System.out.println ("how Many people see the exam?"); int personsum = Input.nextint (); The number of people who obtained this exam from the console System.out.println ("how many questions?"); int tisum = Input.nextint (); Get the number of questions for this exam from the console */* * * Get an array of string representations of the path to the directory where The. TXT file is located * * */string[] Fptah = f1.list (); int a = 0; string[] Path = new String[personsum];//an array of answer files//obtained by The. txt file array for (String str:fptah) {System.out.println (str); if (s Tr.endswith (". Txt")) {path[a] = "e:\\\\exam02\\\\" + str;a++;}} Try {testscore (personsum, tisum, path);//call function method (implement automatic scoring, and statistic correct rate)} catch (ioexception e) {e.printstacktrace ();}} public static void Testscore (int personsum, int tisum, string[] Fptah) throws IoexceptiOn {bufferedreader br = null;//read number BufferedReader BR1 = null;//read Full score (correct answer, compared to Object) bufferedwriter bw = null;//write result try {int sum = 0; Record each Person's total score int jige = 0;//statistical pass number int[] f = new Int[tisum];//record The correct number of questions bw = new BufferedWriter (new FileWriter ("e:\\exam02\ \score.bak ", True));//write The result for (int i = 0; i < fptah.length; i++) {//iterate through the answers of each of the candidates/System.out.println (); br = new Buffer Edreader (new FileReader (fptah[i]));//number of readers (the answer of the test), read System.out.println ("---------------") by line; BR1 = new BufferedReader (new filereader ("e:\\exam02\\ full score. bak"));//read perfect score (correct answer, compared to object), read by Line//System.out.println (files[i].getpath ()); for (int j = 0; J < tisum; J + +) {//iterate through each Line's answer if (br.readline (). trim (). equals (br1.readline (). trim ())) {//the answer to each row is judged to be No equal sum + = 5;//accumulate each Person's score f[j]++;//statistics per question do pair of number}system.out.println ("sum" + sum);//test statement}stringbuffer bs=new stringbuffer (); Bs.append ((fptah[i] + "+" score: "+ sum +" min "). replace (" e:\\\\exam02\\\\ "," ""). replace (". txt", ""). trim ()); SYSTEM.OUT.PRINTLN (bs.tostring ());//test Statement if (sum >=) {jige++///}bw.write (bs.tostring ());//write data to a file (answer log) bw.newline (); sum = 0;//set The total to empty, waiting for the next Cumulative}stringbuffer bs1=new StringBuffer () bs1.append ("total number" + fptah.length + "t" + "passing number" + jige), bw.write (bs1.tostring ());//write data to file (answer Log) Bw.newline (); */* Statistics correct rate traverse each question, count the number of people doing each question, then calculate the correct rate output * * */stringbuffer bs2=null; For (int k = 0; k < tisum; k++) {bs2=new StringBuffer (); System.out.println (f[k]); int t1 = (int) (f[k]/20.0 * 100);//calculate correct rate bs2.append ("question" + (k + 1) + "correct rate =" + t1 + "%");//string ZQL = "question" + (k + 1) + "correct rate for" + t1 + "%";//record The correct rate of each problem bw.write (bs2.tostring ());//write data to file (answer log) bw.newline ();//newline}bw.flush ( );//flush buffer} finally {if (br1! = Null) {br1.close ();} If (br! = Null) {br.close ();} If (bw! = Null) {bw.close ();}}}}
Java Scoring System