java - Compare users input -
i have text.file questions , text.file correct answers questions. program contains jbutton-s , when user clicks on button shows new pane question multiple choice answers, user asked write letter of correct answer. have done things , works. want compare entered answer correct answer , store number of correct answers in text.file
if can give advice or example code appreciate it. thank in advance , here code, need add things.
jtextfield xfield = new jtextfield(5); jpanel mypanel = new jpanel(); mypanel.add(new jlabel("answer: ")); mypanel.add(xfield); mypanel.add(box.createhorizontalstrut(20)); int result = joptionpane.showconfirmdialog(null, mypanel, "please enter answer", joptionpane.ok_cancel_option); return; } } }
i have made similar application years ago. did putting questions answers in text file. first answer correct answer. when question shown on screen (with possible answers), used method change order of possible answers, , remembered number (or letter) of correct answer. then, when received input user, easy compare answer correct answer.
in application, did not ask input letter, used radio buttons, user had select 1. advantage of input key board, user might use upper/lower case, or ad white space, or so, makes correct answer might not recognized. radio buttons easier compare, receive teh number of selected button, without possible unexpected input user.
Comments
Post a Comment