JAVA课程设计

JAVA课程设计

一、团队介绍

二、项目git地址

 https://gitee.com/ZhangRongBo/online_examination_system

三、项目git提交记录截图

 

四、项目结构功能图与主要功能结构图

 项目结构功能图:

主要功能结构图:

五、项目运行截图

1.学生登录界面

 

2.学生注册

3.考试界面

4.成绩查询

5.修改资料

6.管理员登录界面

7.后台管理部分界面

六、项目关键代码

 

public Lesson() {
        this.lessonDAO = new LessonDAO();
    }
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) {
        String action = request.getParameter("action");
        System.out.println("获取的查询字符串:" + action);
        if (action == null || "".equals(action)) {
            return mapping.findForward("error");
        } else if ("lessonQuery".equals(action)) {
            return lessonQuery(mapping, form, request, response);

        } else if ("lessonAdd".equals(action)) {
            return lessonAdd(mapping, form, request, response);
        } else if ("lessonDel".equals(action)) {
            return lessonDel(mapping, form, request, response);
        }else if("selectLesson".equals(action)){
            return selectLesson(mapping, form, request, response);
        }else if("ready".equals(action)){
            return ready(mapping, form, request, response);
        }
        request.setAttribute("error", "操作失败!");
        return mapping.findForward("error");
    }
private ActionForward submitTestPaper(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response){
        QuestionsForm q=(QuestionsForm)form;
        String rightAnswer="";
        float singleMark=0;
        float moreMark=0;
        String[] single=q.getAnswerArrS();
        int[] singleId=q.getIdArrS();
        //System.out.println(q.getID());
        System.out.println("数据的长度:"+single.length);
        float markS=40/(single.length);
        for(int i=0;i<single.length;i++){
            //调用getRightAnswer()方法获取正确答案
            rightAnswer=startExamDAO.getRightAnswer(singleId[i]);
            System.out.println("单选数组:"+i+"********ID号"+singleId[i]+"********"+single[i]+"****正确答案"+rightAnswer);
            if(rightAnswer.equals(single[i])){
                singleMark=singleMark+markS;    //累加单选题的分数
            }            
        }
        System.out.println("单选题得分:"+singleMark);
        MoreSelect[] more=q.getMoreSelect();
        System.out.println("多选数组的长度:"+more.length);
        float markM=60/(more.length);
        String str="";
        for(int i=0;i<more.length;i++){
            String[] ans=more[i].getAnswerArr();
            int[] moreId=q.getIdArrM();
            rightAnswer=startExamDAO.getRightAnswer(moreId[i]);
            System.out.println("多选数组:"+i+"********ID号"+moreId[i]+"********"+more[i]+"****正确答案"+rightAnswer);
            for(int j=0;j<ans.length;j++){
                if(ans[j]!=null) str=str+ans[j]+",";
            }
            if(str.length()>1){
                str=str.substring(0,str.length()-1);
            }
            
            System.out.println("获取的多选题答案:"+str);
            if(rightAnswer.equals(str)){
                moreMark=moreMark+markM;    //累加多选题的分数
            }    
            str="";
        }
        System.out.println("多选题得分:"+moreMark);
        HttpSession session = request.getSession();
        String student=session.getAttribute("student").toString();
        int lessonID=Integer.parseInt(session.getAttribute("lessonID").toString());    //课程ID
        int ret=startExamDAO.saveResult(student,lessonID,(int)Math.round(singleMark),(int)Math.round(moreMark));
        if(ret>0){
            request.setAttribute("submitTestPaperok", "试卷已提交,您本次考试的成绩为:"+(Math.round(singleMark)+Math.round(moreMark))+"分!");
            return mapping.findForward("submitTestPaperok");
        }else{
            return mapping.findForward("dealNull");
        }
    }

}
//找回密码(第一步)
    private ActionForward seekPwd1(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response){
        StudentForm studentForm = (StudentForm) form;
        StudentForm s=studentDAO.seekPwd1(studentForm);
        request.setAttribute("seekPwd2", s);
        if(s.getID().equals("")){
            request.setAttribute("error", "您输入的准考证号不存在!");
            return mapping.findForward("error");
        }else{
            return mapping.findForward("seekPwd1");    
        }
    }
//    找回密码(第二步)
    private ActionForward seekPwd2(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response){
        StudentForm studentForm = (StudentForm) form;
        StudentForm s=studentDAO.seekPwd2(studentForm);
        request.setAttribute("seekPwd3", s);
        if(s.getID().equals("")){
            request.setAttribute("error", "您输入的密码提示问题的答案不正确!");
            return mapping.findForward("error");
        }else{
            return mapping.findForward("seekPwd2");
        }
    }
    public ResultSet executeQuery(String sql) {
        try { // 捕捉异常
            conn = getConnection(); // 调用getConnection()方法构造Connection对象的一个实例conn
            stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                    ResultSet.CONCUR_READ_ONLY);
            rs = stmt.executeQuery(sql);
        } catch (SQLException ex) {
            System.err.println(ex.getMessage()); // 输出异常信息
        }
        return rs; // 返回结果集对象
    }

    public int executeUpdate(String sql) {
        int result = 0; // 定义保存返回值的变量
        try { // 捕捉异常
            conn = getConnection(); // 调用getConnection()方法构造Connection对象的一个实例conn
            stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                    ResultSet.CONCUR_READ_ONLY);
            result = stmt.executeUpdate(sql); // 执行更新操作
        } catch (SQLException ex) {
            result = 0; // 将保存返回值的变量赋值为0
        }
        return result; // 返回保存返回值的变量
    }
<logic:iterate id="questions" name="singleQue" type="com.wgh.actionForm.QuestionsForm" scope="request" indexId="ind">
  <tr>
    <td height=23 colspan="4" align=center nowrap>
      <table width="100%"  border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="8%" align=right height=23>[&nbsp;${ind+1}&nbsp;]</td>
          <td width="2%">&nbsp;</td>
          <td width="90%" align=left nowrap style="font-size:11pt;"><bean:write name="questions" property="subject" filter="true"/>
          <html:hidden property="idArrS[${ind}]" name="questions"/>
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td width="8%" height=23 nowrap>&nbsp;</td>
    <td width="3%" align=center nowrap><html:radio property="answerArrS[${ind}]" styleClass="noborder" value="A"/></td>
    <td width="3%" align=center nowrap>A.</td>
    <td width="86%" align=left nowrap><bean:write name="questions" property="optionA" filter="true"/></td>
  </tr>
  <tr>
    <td width="8%" height=23 nowrap>&nbsp;</td>
    <td width="3%" align=center nowrap><html:radio property="answerArrS[${ind}]" styleClass="noborder" value="B"/></td>
    <td width="3%" align=center nowrap>B.</td>
    <td width="86%" align=left nowrap><bean:write name="questions" property="optionB" filter="true"/></td>
  </tr>
  <tr>
    <td width="8%" height=23 nowrap>&nbsp;</td>
    <td width="3%" align=center nowrap><html:radio property="answerArrS[${ind}]" styleClass="noborder" value="C"/></td>
    <td width="3%" align=center nowrap>C.</td>
    <td width="86%" align=left nowrap><bean:write name="questions" property="optionC" filter="true"/></td>
  </tr>
  <tr>
    <td width="8%" height=23 nowrap>&nbsp;</td>
    <td width="3%" align=center nowrap><html:radio property="answerArrS[${ind}]" styleClass="noborder" value="D"/></td>
    <td width="3%" align=center nowrap>D.</td>
    <td width="86%" align=left nowrap><bean:write name="questions" property="optionD" filter="true"/></td>
  </tr>
  </logic:iterate>

主要截取了一些诸如执行action的代码,以及前端传入form实例类的代码,以及DAO模式的存贮代码和返回后端的代码。

七、项目代码扫描结果及改正

扫描结果:

 改正:

 

八、尚待改进

前端设计的时候并不是使用的动态化设计,并且在设计前端内容的时候没有考虑到整个去应用模块化设计,增加了后续的迭代难度。

后端中实例类的底层架构不够完美,在后续的开发工作中遇到了之前未想到的问题。归根结底是对面向对象编程的不熟悉,对类中属性和类承担的责任的不严谨导致后续迭代产生了困难。最后导致注入单选多选必须同时存在的问题。

部分功能无法实现:学生类中缺少相应的属性,使得管理员不得指定一个学生只能参加特定的考试,或者让该学生补考。

原文地址:https://www.cnblogs.com/k1206/p/10277207.html