import java.io.File;
import java.util.Scanner;
import java.util.ArrayList;


public class Question6 {

	public static void main(String[] args) {
		
		// Instantiate File and Scanner objects
		File foobar;
		Scanner input;
		
		// Set up file
		foobar = new File ("files\\Question6.txt");
		
		// Read file 
		try {
			
			// Set up Scanner
			input = new Scanner(foobar);
			
			// Set up variables
			String correctAnswer;
			ArrayList<String> students = new ArrayList<String>();
			ArrayList<String> answers = new ArrayList<String>();
			ArrayList<Integer> scores = new ArrayList<Integer>();
			String buffer;
			
			// Process scores
			correctAnswer = input.nextLine();
			int scoreBuffer = 0;
			String answerBuffer;
			while (input.hasNext()) {
				
				// Add answers to arraylists
				students.add(input.nextLine());
				answerBuffer = input.nextLine();
				answers.add(answerBuffer);
				
				// Check answers
				for (int i = 0; i < correctAnswer.length(); i++) {
					if (answerBuffer.charAt(i)==correctAnswer.charAt(i)) {
						scoreBuffer++;
					}
				}
				scores.add(scoreBuffer);
				
				// Reset buffers;
				answerBuffer = null;
				scoreBuffer = 0;
			
			}
			
			// Clean up
			input.close();
			
			// Report results
			System.out.println("Correct answer:\n" + correctAnswer + "\n");
			final String format = "%-10s %-1s\n";
			for (int i = 0; i < students.size(); i++) {
				System.out.format(format, "Student:", students.get(i));
				System.out.format(format, "Answer:", answers.get(i));
				System.out.format(format, "Score:", scores.get(i) + "/" + correctAnswer.length());
				System.out.format(format, "Percent:",
						+ (int)(100*(double)(scores.get(i))/(double)(correctAnswer.length()))
						+"%\n"
						);
			}
		
		} catch (java.io.FileNotFoundException e) {
			
			// From "input = new Scanner(foobar);"
			System.err.println("Error: file " + foobar + " not found.");
			e.getMessage();
			System.exit(1);
		}

	}

}
