/* * Written By : Ahmad Jawed ZAFAR * Date : 12/08/2009 * Web Site : www.yashlar.net * Description : In This Program You First Register Exams from Text Files (Maximum of 10 Exams, You Can Increase Them) * : and Store Them, then the User Can Enter Any Registered Exam And Answer Them. Each Question must be In A New Line Inside The .txt File. * : The Answers Are Stored In A Text File Named "Answer" Followed By The Test Name. * Important : You Must Place The Test Files In A Folder Together With The Program. * */ import java.util.*; import java.awt.*; import javax.swing.*; import java.io.*; public class Exam // Main Class { private String[][] questions; // stores questions private String[][] answers; // stores user answers int testNum; // counts the number of test read from files int numQ, numA; // counts the number of questions and answers belong to a specific test. private String testList[]; // stores the names of the tests read from files. private int[] questionNum; // stores the number of questions of test respectively private int numAnsweredTest; // counts the number of test answered by the user private int[] answeredTestOrder; // stores the answered tests respectively public Exam() { // initializing variables. questionNum = new int[100]; testList = new String[10]; questions = new String[10][100]; answers = new String[10][100]; numQ = numA = 0; testNum = 0; numAnsweredTest = 0; answeredTestOrder = new int[10]; } ///----------------------------------------------------------------------------------- public boolean isAlreadyAnswered(int testNum) // checks if a test is already answered { for (int i=0; i testNum) // if user enter an invalid test number (if user tries to enter test number 4 while there are only 3 tests available) { System.out.println("Invalid Test Number"); } else { String ansFile; ansFile = testList[testNtmp] + "Answer.txt"; try { BufferedWriter testAns = new BufferedWriter(new FileWriter(ansFile)); System.out.println("Welcome To " + testList[testNtmp] + " Test, Answer The Following Questions"); System.out.println("--------------------------------------------------------------------------\n"); for (int i=0; i