源码在Github的仓库主页链接地址:https://github.com/ilyar1015/ArithmeticWeb
需求分析
设计开发一个小学生四则运算练习软件,使之具有以下功能:
1. 由计算机从题库文件中随机选择20道加减乘除混合算式,用户输入算式答案,程序检查答案是否正确,每道题正确计5分,错误不计分,20道题测试结束后给出测试总分;
2. 题库文件可采用实验二的方式自动生成,也可以手工编辑生成,文本格式如下:
3. 程序为用户提供三种进阶四则运算练习功能选择:百以内整数算式(必做)、带括号算式、真分数算式练习;
4. 程序允许用户进行多轮测试,提供用户多轮测试分数柱状图,示例如下:
5. 程序记录用户答题结果,当程序退出再启动的时候,可为用户显示最后一次测试的结果,并询问用户可否进行新一轮的测试;
6. 测试有计时功能,测试时动态显示用户开始答题后的消耗时间。
7. 程序人机交互界面是GUI界面(WEB页面、APP页面都可),界面支持中文简体(必做)/中文繁体/英语,用户可以进行语种选择。
软件设计
使用类图:
核心代码:
随机出题:
package com.arithmetic.question; import java.util.ArrayList; public class SetAQuestion { int n; int next,time; String topic; GetRandomDigit grd=null; ArrayList<Topic> al; Topic question; ArithmeticResult ar; public SetAQuestion(int n){ this.n=n; init(); setQuestion(); } private void init(){ grd=new GetRandomDigit(); al=new ArrayList<Topic>(); ar=new ArithmeticResult(); } private void setQuestion(){ //出题的数量 int[] questionTopic;; int[] questionOprator; for(int i=0;i<n;i++){ //出题的长度 time=grd.Time(); questionTopic=new int[time]; questionOprator=new int[time-1]; for(int t=0;t<time;t++){ questionTopic[t]=grd.randomDigit(); if(t<time-1){ questionOprator[t]=grd.oprator(); } } topic=""; int bracketsIndex=-1; if(PQ()){ bracketsIndex=grd.BracketsIndex(time); } for(int t=0;t<time;t++){ if(bracketsIndex==t){ topic=topic+"("; } topic=topic+questionTopic[t]; if(bracketsIndex+1==t && bracketsIndex!=-1){ topic=topic+")"; } if(t<time-1){ topic=topic+getType(questionOprator[t]); } } topic=topic+"="; double a=ar.Result(topic); if(a<0||a%1!=0||a>500){ i--; continue; } question=new Topic(topic,(int)a); al.add(question); } } private String getType(int type){ if(type==1){ return "+"; }else if(type==2){ return "-"; }else if(type==3){ return "×"; }else{ return "÷"; } } private boolean PQ(){ int PQ=grd.probabilityQuestion(); if(PQ<=120){ return true; }else{ return false; } } public ArrayList<Topic> getQuestion(){ return al; } }
将题目以JSON的方式放到HTML页面
package com.arithmetic.question; import java.io.IOException; import java.util.ArrayList; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.xml.bind.ParseConversionEvent; import net.sf.json.JSONArray; public class GuestionToHtml extends HttpServlet{ private static final long serialVersionUID = 1L; private ArrayList<Topic> al=null; SetAQuestion sqt=null; ListToJson ltj; int textTime=1; public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //设置编码 request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); //设置返回文本的类型 response.setContentType("text/json"); String Ttimes=request.getParameter("n"); textTime=Integer.valueOf(Ttimes); initTest(); String jsonString=toJson(); System.out.println(jsonString); response.getWriter().print(jsonString); } private void initTest(){ al=new ArrayList<Topic>(); sqt=new SetAQuestion(textTime); ltj=new ListToJson(); } private String toJson(){ al=sqt.getQuestion(); // String JSON="{\"topic0\":"+"\""+al.get(0).getTopic()+"\",\"result0\":"+"\""+al.get(0).getResult()+"\""; // for(int i=1;i<al.size();i++){ // JSON=JSON+",\"topic"+i+"\":\""+al.get(i).getTopic()+"\",\"result"+i+"\":\""+al.get(0).getResult()+"\""; // } JSONArray JSON=ltj.LTJ(al); return JSON.toString(); } }
验证登录
package com.arithmetic.sql; import java.io.IOException; import java.sql.ResultSet; import java.sql.SQLException; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @WebServlet("/Login") public class Logined extends HttpServlet { private static final long serialVersionUID = 1L; LinkSql ls; String jsonString; public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //设置编码 request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); //设置返回文本的类型 response.setContentType("text/json"); initTest(); String name=request.getParameter("name"); String password=request.getParameter("password"); System.out.println(name+" ++ "+password); if(logined(name,password)){ jsonString="{\"massage\":true}"; }else{ jsonString="{\"massage\":false}"; } System.out.println(jsonString); response.getWriter().print(jsonString); } private void initTest(){ ls=new LinkSql(); } private boolean logined(String name,String password){ ResultSet rs=ls.selectSqlDate(String.format("select * from user where name='%s'", name)); try { while(rs.next()){ if(rs.getString("name").equals(name)&&rs.getString("password").equals(password)){ return true; }else{ return false; } } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return false; } }
出题见面 ajax
var res; function getQuestion(){ var questionTime=$('#questionTime').val(); $.ajax({ type:"GET", url:"GuestionToHtml", data:"n="+questionTime, datatype:"text/json", success:function(result){ $("#result").attr({ disabled: "value" }); res=result; $('#question').text(""); for(var i=0;i<result.length;i++){ if(i%2==0){ $('#question').append('<li class="list-group-item col-md-6 fl" style="height: 50px;">' +'<div class="form-group fl">' +'<label for="inputEmail3" class="col-sm-4 control-label" style="margin-top: 5px;">'+result[i].topic+'</label>' +'<div class="col-sm-1">' +'<input type="number" style="width: 100px;" class="form-control" '+'id="'+'q'+i+'"'+' placeholder="答案">' +'</div>' +'</div>' +'</li>'); }else{ $('#question').append('<li class="list-group-item col-md-6 fr" style="height: 50px;">' +'<div class="form-group fl">' +'<label for="inputEmail3" class="col-sm-4 control-label" style="margin-top: 5px;">'+result[i].topic+'</label>' +'<div class="col-sm-1">' +'<input type="number" style="width: 100px;" class="form-control" '+'id="'+'q'+i+'"'+' placeholder="答案">' +'</div>' +'</div>' +'</li>'); } } }, error:function(result){ alert("服务器出现异常"); } }); }
各模块界面:
登录:
答题:
统计结果:
学生注册:
e.描述结对的过程,提供两人在讨论、细化和编程时的结对照片(非摆拍)。
由于我们采用的是分工合作的方法完成项目,彼此不熟悉彼此的代码风格,两个人也没有花时间去磨合,只是完成一个简单的初期想法就开始各自做代码。在这期间,队友给我带来了很多的新思路,但同时呢,也出现过两个人彼此误导,在长时间编程以后两个人都陷入了错误之中。两个人也都在磨合之中,逐渐提高了Java的编程能力。
f.提供此次结对作业的PSP。
PSP2.1 | 任务内容 | 计划共完成需要的时间(min) | 实际完成需要的时间(min) |
Planning | 计划 | 8 | 6 |
· Estimate | · 估计这个任务需要多少时间,并规划大致工作步骤 | 8 | 6 |
Development | 开发 | 148 | 407 |
·· Analysis | 需求分析 (包括学习新技术) | 6 | 10 |
· Design Spec | · 生成设计文档 | 5 | 6 |
· Design Review | · 设计复审 (和同事审核设计文档) | 4 | 6 |
· Coding Standard | 代码规范 (为目前的开发制定合适的规范) | 3 | 3 |
· Design | 具体设计 | 10 | 12 |
· Coding | 具体编码 | 100 | 300 |
· Code Review | · 代码复审 | 7 | 10 |
· Test | · 测试(自我测试,修改代码,提交修改) | 13 | 60 |
Reporting | 报告 | 9 | 6 |
·· Test Report | · 测试报告 | 3 | 2 |
· Size Measurement | 计算工作量 | 2 | 1 |
· Postmortem & Process Improvement Plan | · 事后总结 ,并提出过程改进计划 | 3 | 3 |
g. 请使用汉堡评价法给你的小伙伴一些点评。
在两人合作当中,发现队友对界面设计,以及对色彩搭配做的好,发现我对界面设计美观方面还是有些障碍,而界面在用户体验中往往是很重要的,有些设计思路方面也比较清晰,这次两人合作各补各自的缺点,我希望下次继续合作下去。
h. 结对编程真的能够带来1+1>2的效果吗?通过这次结对编程,请谈谈你的感受和体会。
在这次的结队编程当中,我发现带来的效果是1+1>2。在以往的编程当中,我几乎都是就我一个人设计,设计界面,敲代码,找bug什么的,往往是不能够很好的展现出所做出来的东西,前期还是感觉不出来,估计因为写的代码太简单了,行数太短。到后来发现了一些问题。在这次的结对项目后,觉得两人带来的效果比一个人好多了。在这次的结对项目中我们进行了一次的挑战,我们之前没有学过用java写网页,使用ajax请求时获取的方法,也没有试过用GitHub同步俩人的代码(GitHub同步代码比用U盘或者QQ传到对方电脑的方式好多了)。我们决定使用java写网页,后来通过两人的多方面查资料,边学边做,遇到的bug一起解决,解决问题的方法相对与以前的方法速度快,效率高。