您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 信息化管理 > 在线考试系统--简单java代码
OnlineExamQuestions()***************************************************************Index.javaimportjava.io.BufferedReader;importjava.io.InputStreamReader;publicclassIndex{staticintadminMenu(){intchoice=0;try{BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));System.out.println(1.RegisterQustions);System.out.println(2.StartExam);System.out.println(3.Getout);choice=Integer.parseInt(br.readLine());}catch(Exceptione){System.out.println(Enteriserror);}returnchoice;}publicstaticvoidmain(String[]args){System.out.println(WelcometoOnlineExamSystem);intchoice;do{choice=adminMenu();switch(choice){case1:Questionsbr=newQuestions();br.QuestionList();break;case2:Questionstemp=newQuestions();temp.exam();break;}}while(choice!=3);System.out.println(ThankYou!!!);}}*******************************************************questions.javaimportjava.io.BufferedReader;importjava.io.InputStreamReader;importjava.util.ArrayList;importjava.util.HashSet;importjava.util.Iterator;importjava.util.Random;publicclassQuestions{intquestionNumber;Stringquestion;StringoptionA;StringoptionB;StringoptionC;StringoptionD;StringcorrectOption;staticintQnumber;staticArrayLista1=newArrayList(10);booleanb=true;voidQuestionList(){try{BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));System.out.println(EnterQuestionNumber:);this.questionNumber=Integer.parseInt(br.readLine());if(Qnumber!=0){for(inti=0;iQnumber;i++){Questionsq=(Questions)a1.get(i);if(this.questionNumber==q.questionNumber){System.out.println(questionNumberisextist);b=false;break;}}}if(b){System.out.println(EnterQuestion:);this.question=br.readLine();System.out.println(EnterOption-A:);this.optionA=br.readLine();System.out.println(EnterOption-B:);this.optionB=br.readLine();System.out.println(EnterOption-C:);this.optionC=br.readLine();System.out.println(EnterOption-D:);this.optionD=br.readLine();System.out.println(EntercorrectAnswer:);this.correctOption=br.readLine();question();}}catch(Exceptione){System.out.println(Enterhandledtheexception);}}voidquestion(){Questionsq1=newQuestions();q1=this;a1.add(q1);Qnumber++;System.err.println(Registersuccess);System.out.println(TotalQuestionsRegistered=+Qnumber);}voidexam(){if(Qnumber!=0){System.out.println(StartExam);if(Qnumber5){System.out.println(Howmanyquestions:+(Qnumber));}else{System.out.println(Howmanyquestions:5);}Randomrandom=newRandom();HashSeth1=newHashSet();for(inti=0;i5;i++){h1.add(random.nextInt(Qnumber));}Iteratoriterator=h1.iterator();while(iterator.hasNext()){Questionsq1=(Questions)a1.get((Integer)iterator.next());System.out.print(q1.questionNumber+.);System.out.println(q1.question);System.out.println(A:+q1.optionA);System.out.println(B:+q1.optionB);System.out.println(C:+q1.optionC);System.out.println(D:+q1.optionD);System.out.println(EnterCorrectOption:);try{BufferedReaderbReader=newBufferedReader(newInputStreamReader(System.in));Stringtemp=bReader.readLine();if(temp==q1.correctOption){System.out.println(Right);}else{System.out.println(Wrong);}}catch(Exceptione){System.out.println(Enterhandledtheexception);}}}else{System.out.println(NoQuestions);}}}
本文标题:在线考试系统--简单java代码
链接地址:https://www.777doc.com/doc-5820656 .html