MCQ Quiz program using Java language
<p>I have program using Java language ;this program write MCQ quiz and should also mention the correct answer and save the data all this in option no.1
In option no.2 this contain method that is called start quiz,(it can start Quiz after write Question from Administration or who know the password ,if choose this option Before write Question it will give error) 
option no.3 exit from program</p>

<p>My problem is :</p>

<ol>
<li><p>after write each question in option no.1 it save but I want to see all questions in the end after finish it (write all of them in the end, not as a separate one)</p></li>
<li><p>method start quiz is not work (i want to use the variable that is in create Question method"option no.1" called result because if this result is false 'I will not start quiz' because no Question written in the application .But if it is true ' I can start Quiz and measure the marks'
but if I want to use this variable  should write it as public static but in this condition it give error out put in option no.1 !!!</p></li>
</ol>

<p>This is my program:</p>

<p>The main</p>

<pre><code>if (allow == 1) //allow to create questions
{
    boolean res = z.createQuestions();
    if (res == false) {
        System.out.println("Unable to continue execution. Please try again...!");
    }
} else {
    ch = 0;
}

/* case 2: core quiz contest routine
int r = z.startQuiz();
switch(r) {
    case 0:
        msg = "";
        break;
    case 1:
        msg = "\nUnable to start the quiz.\n";
        msg = msg + "Please make sure the file exists in the ";
        msg = msg + "application path.\n";
        msg = msg + "If you are unable to locate the file, please hit OPTION 1 and ";
        msg = msg + "create a new file.";
        break;
    case 2:
        msg = "\nUnable to start the quiz.\n";
        msg = msg + "Please make sure the file is not empty and it is valid in ";
        msg = msg + "the application path. Otherwise hit OPTION 1 and create a new file.";
        break;
    case 3:
        msg = "Sorry, the program is interrupted due to in-process exception...!";
        break;
}

if (!msg.equals("")) {
    System.out.println(msg);
}

break;*/
</code></pre>

<p>Class quiz:</p>

<pre><code>//create and save questions
//returns true if successfull else returns false
public boolean createQuestions() {
    int go = 0, saved = 0;
    boolean ret = false;
    String[] ques;
    String msg = "";
    boolean result = false;
    while (result == false) {
        System.out.print("\n Please mention no. of questions to store");
        System.out.print("\n [Enter 0 to skip this step] : ");
        nos = br.readLine();

        result = isNum(nos);

        if (result == false) {
            System.out.println("The input should be an positive integer only...!");
        } else {
            if (nos.equals("0")) {
                go = 0;
            } else {
                go = 1;
            }
        }
    }

    if (go == 0) {
        ret = true;
    } else {
        for (int i = 1; i &lt;= Integer.parseInt(nos); i++) {
            saved = 0;
            ques = new String[6];
            while (saved != 1) {
                msg = "";
                br = new BufferedReader(ir);
                //question body
                System.out.print("\n Please type Question No. " + i + " : ");
                ques[0] = br.readLine();
                //choice 1
                System.out.print("\n Option 1 : ");
                ques[1] = br.readLine();
                //choice 2
                System.out.print("\n Option 2 : ");
                ques[2] = br.readLine();
                //choice 3
                System.out.print("\n Option 3 : ");
                ques[3] = br.readLine();
                //choice 4
                System.out.print("\n Option 4 : ");
                ques[4] = br.readLine();
                //correct answer
                System.out.print("\n Correct Answer(Mention option no. only) : ");
                ques[5] = br.readLine();

                //validating input
                if (ques[0].equals("")) {
                    msg = "The question body should not be blank...!\n";
                }
                for (int j = 1; j &lt;= 4; j++) {
                    if (ques[j].equals("")) {
                        msg = msg + "Option " + j + " should have been mentioned...!\n";
                    }
                }
                if (isNum(ques[5]) == false) {
                    msg = msg + "The input for correct answer should be an integer...!\n";
                } else {
                    if (Integer.parseInt(ques[5]) &gt;= 1 &amp;&amp; Integer.parseInt(ques[5]) &lt;= 4) {
                        //do nothing, the input for correct answer is okey 
                    } else {
                        msg = msg + "Invalid answer indication no. It must be within 1 and 4...!";
                    }
                }

                //data violated according to rule, so display the errors
                if (!msg.equals("")) {
                    System.out.print("\n The following mistakes have been occured :-");
                    System.out.print("\n --------------------------------------------");
                    System.out.print("\n " + msg);
                    saved = 0;
                } else {
                    //save the question and proceed
                    try {

                        Scanner in = new Scanner(System.in);
                        System.out.println(ques[0] + "," + ques[1] + "," + ques[2] + "," + ques[3] + "," + ques[4] + "," + ques[5]);

                        System.out.println("Successfully saved...");
                        saved = 1;
                    }


//start the quiz contest module
/*
public int startQuiz() {
    boolean r = true;

    if (result == false) {
        retVal = 1;
    } else {

        //displaying questions to the user and respective actions
        for (int i = 0; i &lt; nos; i++) {
            question = new String[6];

            while (commit != 1) {
                try {
                    System.out.print("\n Question No. " + (i + 1));
                    System.out.print("\n ------------------");
                    System.out.print("\n " + question[0]);
                    System.out.print("\n Option 1 --&gt;" + question[1]);
                    System.out.print("\n Option 2 --&gt;" + question[2]);
                    System.out.print("\n Option 3 --&gt;" + question[3]);
                    System.out.print("\n Option 4 --&gt;" + question[4]);
                    if (retVal == 0) {
                        System.out.println("\n CONTEST RESULT");
                        System.out.println("\n ------------------------------");
                        System.out.println("\n No. of Question(s) Presented = " + nos);
                        System.out.println("\n No. of Question(s) Attempted = " + attempted);
                        System.out.println("\n No. of Question(s) Skipped = " + skipped);
                        System.out.println("\n Correct Answers = " + correct);
                        System.out.println("\n Wrong Answers = " + wrong);
                        if (attempted != 0) {
                            System.out.println("\n Accuracy Percentage = " + (correct * 100) / attempted + "%\n");
                        } else {
                            System.out.println("\n Accuracy Percentage = Not Calculated\n");
                        }

                        if (!summary.equals("")) {
                            System.out.println("\n\n Correct Answer(s) of Wrong answered question(s) :-\n");
                            System.out.print("--------------------------------------------------------\n");
                            System.out.print(summary + "\n");
                        }
                        System.out.print("--------------------------------------------------------\n\n");
                    }
                }
                return retVal;
            }
        }*/
</code></pre>

<p>Thank you </p>
