Please help me display the output in if else loop ,
September 22, 2009 at 8:37 PM
I would like to know how do I display the output the one's that come under this method using JLabel which comes under if else loop "Correct" & if it's wrong " ("Sorry! The correct answer is c \n")" & "("Congratulations,you passed with a score of "+score+ "%\n");"
public void itemStateChanged(ItemEvent e) { int numberCorrect=0; int score;
Checkbox user1Selection = ques1Grp.getSelectedCheckbox(); System.out.println(user1Selection); if(user1Selection == c1)// checks whether the answer matches { System.out.println ("Correct");//displays correct if the answer matches numberCorrect++; // adds 1 to the number of correct answers }else System.out.println("Sorry! The correct answer is c \n"); // if the answer is incorrect displays the correct answer
Checkbox user2Selection = ques2Grp.getSelectedCheckbox(); System.out.println(user2Selection); if(user2Selection == b2)// checks whether the answer matches { System.out.println("Correct");//displays correct if the answer matches numberCorrect++; // adds 1 to the number of correct answers }else System.out.println("Sorry! The correct answer is b \n"); // if the answer is incorrect displays the correct answer
Checkbox user3Selection = ques3Grp.getSelectedCheckbox(); System.out.println(user3Selection); if(user3Selection == a3)// checks whether the answer matches { System.out.println("Correct");//displays correct if the answer matches numberCorrect++; // adds 1 to the number of correct answers }else System.out.println("Sorry! The correct answer is a \n"); // if the answer is incorrect displays the correct answer
Checkbox user4Selection = ques4Grp.getSelectedCheckbox(); System.out.println(user4Selection); if(user4Selection == c4)// checks whether the answer matches { System.out.println("Correct");//displays correct if the answer matches numberCorrect++; // adds 1 to the number of correct answers }else System.out.println("Sorry! The correct answer is c \n"); // if the answer is incorrect displays the correct answer
Checkbox user5Selection = ques5Grp.getSelectedCheckbox(); System.out.println(user5Selection); if(user5Selection == d5)// checks whether the answer matches { System.out.println("Correct");//displays correct if the answer matches numberCorrect++; // adds 1 to the number of correct answers }else System.out.println("Sorry! The correct answer is d \n"); // if the answer is incorrect displays the correct answer System.out.println("\n You had "+numberCorrect+" question correct.\n");// displays number of questions correct
score = (numberCorrect*20);//score calculation if (score>=60) { // Displays the end result if the user scores >= 60 it congratulates them or if it's <60 displays better luck next time. System.out.println("Congratulations,you passed with a score of "+score+ "%\n"); }else{ System.out.println("Sorry, your grade was "+score+"% Better luck next time!");