软件工程结对作业01

队员:     信1505-1         20153144         毛松林

                   信1505-1         20153                张浩

程序设计思想

       这次的任务是团队开发一个能实现自动生成算术题,并且能够检查结果和将结果存放到数据库中的四则运算网站。程序的业务逻辑已经在前面的实验中完成了,现在只需要实现应用的控制逻辑和界面显示就行了。我和我的伙伴选择用MVC结构构建Web应用程序。网页的设计思路大致为首先显示一个数据设置界面,让用户控制需要的到的表达式的各种参数,然后将参数传递给后台运行的servlet,servlet接受到参数后调用JavaBean的相关类,生成符合参数要求的表达式,并且将表达式存放到数据库中,接着servlet将表达式存放到jsp页面的请求对象中并且转发请求到显示表达式的界面。然后提交的答案会再次传送到后台然servlet判断回答是否正确,最后跳转到界面显示答题的结果。

程序源代码:

参数设置界面HTML代码:

 1 <body>
 2 <div id = "inputDiv">
 3     <form name="form1" action="EquationServlet" method="post">
 4         <table>
 5             <caption>表达式参数设置</caption>
 6             <tr>
 7                 <th>选项</th><th>设置</th>
 8             </tr>
 9             <tr>
10                 <td><label for="name">表达式个数:</label></td>
11                 <td><input type="number" name="sum"size="3"></td>
12             </tr>
13             <tr>
14                 <td><label for="operandsum">操作数个数:</label></td>
15                 <td><input type="number" name="operandsum"size="3"></td>
16             </tr>
17             <tr>
18                 <td><label for="maxinteger">整数最大值:</label></td>
19                 <td><input type="number"name="maxinteger"size="3"></td>
20             </tr>
21             <tr>
22                 <td><label for="maxnumerator">分子最大值:</label></td>
23                 <td><input type="number"name="maxnumerator"size="3"></td>
24             </tr>
25             <tr>
26                 <td><label for="maxdenominator">分母最大值:</label></td>
27                 <td><input type="number"name="maxdenominator"size="3"></td>
28             </tr>
29             <tr>
30                 <td><label for="includemultiply">是否包含乘除法:</label></td>
31                 <td><input type="radio" name="includemultiply"value="true"><input type="radio" name="includemultiply"value="false"></td>                
32             </tr>
33             <tr>
34                 <td><label for="withbracket">是否包含括号:</label></td>
35                 <td><input type="radio" name="withbracket"value="true"><input type="radio" name="withbracket"value="false"></td>
36             </tr>
37             <tr>
38                 <td colspan="2"><input type="reset" value="重设"><input type="submit"value="确定"></td>
39             </tr>
40         </table>
41     </form>
42 </div>

答题界面JSP代码:

 1 <body>
 2 <div>
 3     <c:out value="共${questionsum }道计算题,正确${correctsum }道,错误${wrongsum }道。"/>
 4     <a href="thirdpage.jsp">返回首页</a>
 5     <table border="1" cellspacing="0"cellpadding="10px"align="center">
 6         <tr>
 7             <th>题号</th><th>题目</th><th>回答</th><th>正确答案</th><th>批改</th>
 8         </tr>
 9         <%! int i; String str;%>
10         <% i=0; %>
11         <c:forEach items="${list}" var="currentObject" varStatus="statusTag">
12             
13             <tr>
14                 <td>${statusTag.index+1 }</td>
15                 <td>${currentObject.express }</td>
16                 <td>
17                     <%
18                         str = (String)request.getAttribute("answer"+i);
19                         out.print(str);
20                         i++;
21                         request.setAttribute("str", str);
22                     %>
23                 </td>
24                 <td>${currentObject.value }</td>
25                 <td>
26                     <c:if test="${currentObject.value==str }"><font color="green">正确</font></c:if>
27                     <c:if test="${currentObject.value!=str }"><font color="red">错误</font></c:if>
28                 </td>
29             </tr>
30         </c:forEach>
31     </table>
32 </div>
33 </body>

显示结果界面JSP代码:

 1 <div id="resultDiv"align="center">
 2 <form name="form2" action="CheckAnswerServlet" onsubmit=""method="post">
 3     <table style="align:center; cellspacing:0px; padding=12px; border: 3px #ff00ff solid;">
 4         <c:forEach items="${list }" var="cur" varStatus="curStatus">
 5             <tr>
 6                 <td>${curStatus.index+1 }.&nbsp;&nbsp;</td>
 7                 <td>${cur.express }&nbsp;&nbsp;=&nbsp;&nbsp;</td>
 8                 <td>
 9                     <input type="text"name="${curStatus.index }"size="8">
10                 </td>
11             </tr>
12         </c:forEach>
13         <tr>
14             <td colspan="2">
15                 <input type="reset" value="重置"> 
16                 <input id="handin" type="button"value="提交">
17             </td>
18         </tr>
19     </table>
20 </form> 
21 </div>

控制器servlet生成表达式,存放到数据库中的代码:

 1 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 2         // TODO Auto-generated method stub
 3         response.setContentType("text/html;charset = utf-8");
 4         request.setCharacterEncoding("utf-8");
 5         String sheng = request.getParameter("includemultiply");//是否有乘除法
 6         String geshu = request.getParameter("sum");//表达式个数
 7         String czush = request.getParameter("operandsum");//操作数个数
 8         String zheng = request.getParameter("maxinteger");//整数最大值
 9         String fenzi = request.getParameter("maxnumerator");//分子最大值
10         String fenmu = request.getParameter("maxdenominator");//分母最大值
11         String kuoha = request.getParameter("withbracket");//是否有括号
12         if(sheng==null||sheng.equals(""))
13             sheng = "true";
14         if(geshu==null||geshu.equals(""))
15             geshu = "1";
16         if(czush==null||czush.equals(""))
17             czush = "4";
18         if(zheng==null||zheng.equals(""))
19             zheng = "100";
20         if(fenzi==null||fenzi.equals(""))
21             fenzi = "10";
22         if(fenmu==null||fenmu.equals(""))
23             fenmu = "10";
24         if(kuoha==null||kuoha.equals(""))
25             kuoha = "true";
26         boolean includemultipy = Boolean.parseBoolean(sheng);
27         int sum = Integer.parseInt(geshu);
28         int operandsum = Integer.parseInt(czush);
29         int maxinteger = Integer.parseInt(zheng);
30         int numerator = Integer.parseInt(fenzi);
31         int denominator = Integer.parseInt(fenmu);
32         boolean withbracket = Boolean.parseBoolean(kuoha);
33         ArrayList<Equation> list = new ArrayList<Equation>();
34         
35         for(int i = 0; i < sum; i++)
36         {
37             Equation array = new Equation(includemultipy,operandsum,maxinteger,
38                     numerator,denominator,withbracket);
39             boolean flag = Action.insertExpress(array);
40             if(!flag)
41                 i--;
42             else
43                 list.add(array);
44         }
45         request.getSession().setAttribute("list", list);
46         request.getRequestDispatcher("showEquation.jsp").forward(request, response);
47     }

验证表达式结果的,更新数据库的java代码:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        response.setContentType("text/html;charset = utf-8");
        request.setCharacterEncoding("utf-8");
        HttpSession session = request.getSession();
        
        @SuppressWarnings("unchecked")
        java.util.ArrayList<third.Equation> list = 
                (java.util.ArrayList<third.Equation>)session.getAttribute("list");
        int questionsum = list.size(),rightsum=0,wrongsum=0;
        String tempexpress,tempanswer=null,tempresult;
        int i = 0;
        do{
            third.Equation exp = list.get(i);
            tempanswer   = request.getParameter(""+i);
            tempexpress = exp.getExpress();
            tempresult = exp.getValue();
            
            request.setAttribute("answer"+i, tempanswer);
            
            i++;
            boolean flag = tempanswer.equals(tempresult);//check the answer is right or not
            if(flag)
                rightsum++;
            Action.updateAnswerRecord(tempexpress, flag);//update the relevant data in the database
        }while(i<questionsum);
        wrongsum= questionsum-rightsum;
        request.setAttribute("list", list);
        request.setAttribute("questionsum", questionsum);
        request.setAttribute("correctsum", rightsum);
        request.setAttribute("wrongsum", wrongsum);
        request.getRequestDispatcher("showResult.jsp").forward(request, response);
    }

 

程序结果截图:

参数设置界面:

 

答题界面:

 

 

结果验证界面:

 

 

 

 

编程总结

         这是我首次结对完成任务。对于从小就被教育万事要独立完成的我,的确有些不适应这样的开发过程。我和我的伙伴对于任务的设计思路还是一致的,但是缺乏沟通交流,缺少真正的协同作战。大概就是分工后各干各的,遇到问题也习惯独立思考。如果按照老师的要求,这应该就是没有达到结对开发的效果吧。不过这是第一次应该是让我们先适应适应吧,以后总会好的。

 

 

 

 

PSP记录表格。

开发前的估计:

PSP2.1

Personal Software Process Stages

Time

Planning

计划

20h 

  · Estimate

  · 估计这个任务需要多少时间

 20h

Development

开发

 15h

  · Analysis

  · 需求分析 (包括学习新技术)

 2h

  · Design Spec

  · 生成设计文档

 1h

  · Design Review

  · 设计复审 (和同事审核设计文档)

 1h

  · Coding Standard

  · 代码规范 (为目前的开发制定合适的规范)

 1h

  · Design

  · 具体设计

 2h

  · Coding

  · 具体编码

 4h

  · Code Review

  · 代码复审

 1h

  · Test

  · 测试(自我测试,修改代码,提交修改)

 3h

Reporting

报告

 5h

  · Test Report

  · 测试报告

 2

 

合计

 20h

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 实际开发记录:

PSP2.1

Personal Software Process Stages

Time

Planning

计划

 

  · Estimate

  · 估计这个任务需要多少时间

 

Development

开发

 10h

  · Analysis

  · 需求分析 (包括学习新技术)

 0

  · Design Spec

  · 生成设计文档

 0

  · Design Review

  · 设计复审 (和同事审核设计文档)

 0

  · Coding Standard

  · 代码规范 (为目前的开发制定合适的规范)

 0

  · Design

  · 具体设计

 2h

  · Coding

  · 具体编码

 4h

  · Code Review

  · 代码复审

 0

  · Test

  · 测试(自我测试,修改代码,提交修改)

 2h

Reporting

报告

 2h

  · Test Report

  · 测试报告

 

  · Size Measurement

  · 计算工作量

 1h

  · Postmortem & Process   Improvement Plan

  · 事后总结, 并提出过程改进计划

 1h

 

合计

 12h

posted @ 2017-04-07 18:50  悦尔  阅读(165)  评论(0编辑  收藏  举报