📄 webtestbean.java
字号:
package webtest;import java.sql.*;//import java.math.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: 天津财经学院 信息管理与信息系统——高职升本0101班 * @author 王刚 * @version 1.0 */public class WebTestBean { private String userName=null;//@用户姓名 userName private int[] questionID;//@问题索引数组 questionID private int index=1;//游标 private String question="";//问题内容 private String[] answer;//选择答案 private int classis=0;//问题分类 private String[] questionAns;//答案 private String studentID=null;//学号 private String errorMessage=null;//错误信息 private int questionCount=0; private long nowtime=5400; private boolean start=false; String questionclassname[]; int questionclass[]; int questionclasses=0; public String getQuestionclassname(int newValue){ return questionclassname[newValue-1]; } public int getClassis(){ return classis;} public int getQestionCount(){ return questionCount;} public boolean getStart(){ return start;} public void start(){ try { Thread a =new Thread (new clock ()); start=true; a.start(); } catch(Exception e) { e.printStackTrace(); } } public void setNowtime(long newValue) { nowtime=newValue; } public long getNowtime() { return nowtime; } public void setStudentID(String newValue) { studentID=newValue; } public WebTestBean() { answer=new String[4]; } public void setUserName(String newValue){ userName=newValue; } public String getAnswer(int ansIndex){ return answer[ansIndex-1]; } public void setQuestionAns(String newValue){ questionAns[index-1]=newValue; } public int whatNull(){ int quatity=0; for (int i=0;i<questionCount;i++) { if(questionAns[i]==null) {quatity++;} } return quatity; } public String getQuestionAns(){ return questionAns[index-1]; } public String getQuestionAns(int qindex){ return questionAns[qindex-1]; } public String[] getAnswer(){ return answer; } public String getUserName(){ return userName; } public void setIndex(int newValue){ index=newValue; if(index<=20) classis=questionclass[0]; else if(index<=40) classis=questionclass[1]; else classis=questionclass[2]; } public int getIndex(){ return index; } public String getErrorMessage(){ return errorMessage; } public String getQuestion(){ Sql_data query=new Sql_data(); String sqlstr="select * from testpaper where questionID="+questionID[index-1]; try { ResultSet rs=query.executeQuery(sqlstr); while(rs.next()){ question=rs.getString("content").trim(); if(classis!=3){ answer[0]=rs.getString("choice1").trim(); answer[1]=rs.getString("choice2").trim(); answer[2]=rs.getString("choice3").trim(); answer[3]=rs.getString("choice4").trim(); } } rs.close(); query.close(); } catch(SQLException e){ System.out.println(e.getMessage()); } return question; } public void selectquestion(){ int rowcount=0; int index=0; int rtn=0; questionclasses=0; questionclass=new int[4]; questionclassname=new String[4]; int[] questionrow=new int[3]; Sql_data query=new Sql_data(); String sqlstr="select * from questionclass"; try{ query.getConn(); ResultSet rs=query.query(sqlstr); while(rs.next()){ questionclass[questionclasses]=rs.getInt("classID"); questionclassname[questionclasses]=rs.getString("classname"); questionclasses++; } } catch(SQLException e) { System.out.println(e.getMessage()); } questionCount=questionclasses*20; questionID=new int[questionCount]; questionAns=new String[questionCount]; int[][] questionindex=new int[3][4000]; sqlstr="select questionID from testpaper where classID=1"; try { ResultSet rs=query.query(sqlstr); rtn=0; while(rs.next()) { questionindex[0][rtn]=rs.getInt("questionID"); rtn++; } } catch(SQLException e) { } questionrow[0]=rtn; sqlstr="select questionID from testpaper where classID=2"; try { ResultSet rs=query.query(sqlstr); rtn=0; while(rs.next()) { questionindex[1][rtn]=rs.getInt("questionID"); rtn++; } } catch(SQLException e) { } questionrow[1]=rtn; sqlstr="select questionID from testpaper where classID=3"; try { ResultSet rs=query.query(sqlstr); rtn=0; while(rs.next()) { questionindex[2][rtn]=rs.getInt("questionID"); rtn++; } } catch(SQLException e) { } questionrow[2]=rtn; for(int l=0;l<questionclasses;l++){ rowcount=questionrow[l]; if(rowcount<20){ questionclass[l]=questionclass[l+1]; questionclassname[l]=questionclassname[l+1]; continue; } do { index=(int)(Math.random()*rowcount)+1; } while(index==0); questionID[0+20*l]=questionindex[l][index-1]; for (int i=1;i<20;i++){ index=(int)(Math.random()*rowcount)+1; questionID[i+20*l]=questionindex[l][index-1]; for (int j=0;j<i;j++){ if (questionID[i+20*l]==questionID[j+20*l]||index==0){ i--;break;} } } } System.out.println("congratulation"); } public int updateAns() { String sqlstr=""; String flag=null; Sql_data query=new Sql_data(); for(int i=0;i<questionCount;i++) { if(questionAns[i]==null) questionAns[i]=""; sqlstr="insert into test(StudentID,questionID,answer) values('"+studentID.trim()+"','"+questionID[i]+"','"+questionAns[i]+"')"; query.executeInsert(sqlstr); query.closeconn(); } return 1; }; class clock implements Runnable { long time=nowtime; clock (){} public void run () { while (time>0) { try { Thread.sleep(1000); } catch (Exception e) {} time=time-1; setNowtime(time); } int i=updateAns(); if(i==1) errorMessage="您的考试时间已到,答案已自动保存。谢谢您的使用,再见!"; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -