设计思想
使用随机数生成第一位和第二位的数和计算符号。之后先计算结果,如果结果在100范围以内则输出算式,否则重新生成算式。直到有效数量到达要求的数量为止。
源程序代码
package com.kao.msg.dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import java.util.Random; import com.kao.msg.Util.DBUtil; import com.kao.msg.model.Suanshi; public class JisuanDao implements IYunsuan { //@Override static int[] id=new int[100]; static int shu=0; public void add(Suanshi suanshi) { Connection connection = DBUtil.getConnection(); String sql ; PreparedStatement preparedStatement = null; ResultSet resultSet = null; sql = "insert into t_sizeyunsuan(firstnum,operator,secondnum,result) values (?,?,?,?)"; try { preparedStatement = connection.prepareStatement(sql); String str=""; preparedStatement.setInt(1, suanshi.getFirstnum()); preparedStatement.setString(2, str+suanshi.getOperator()); preparedStatement.setInt(3, suanshi.getSecondnum()); preparedStatement.setInt(4, suanshi.getResult()); preparedStatement.executeUpdate(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { //关闭资源 DBUtil.close(resultSet); DBUtil.close(preparedStatement); DBUtil.close(connection); } } @Override public Suanshi load(int id) { // TODO Auto-generated method stub Connection connection = DBUtil.getConnection(); String sql = "select * from t_sizeyunsuan where id = ?"; PreparedStatement preparedStatement = null; ResultSet resultSet = null; Suanshi suanshi=null; try { preparedStatement = connection.prepareStatement(sql); preparedStatement.setInt(1, id); resultSet = preparedStatement.executeQuery(); while(resultSet.next()){ String str=""; suanshi=new Suanshi(); suanshi.setFirstnum(resultSet.getInt("firstnum")); suanshi.setOperator(resultSet.getString("operator").charAt(0)); suanshi.setSecondnum(resultSet.getInt("secondnum")); suanshi.setResult(resultSet.getInt("result")); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally { DBUtil.close(resultSet); DBUtil.close(preparedStatement); DBUtil.close(connection); } return suanshi; } public List<Suanshi> load1(int n) { //集合中只能放入user对象 shu=n; List<Suanshi> suanshis = new ArrayList<Suanshi>(); Suanshi suanshi = null; JisuanDao jisuandao=new JisuanDao(); int i=0; int[] a=new int [1000000]; while(i<n){ suanshi=new Suanshi(); Random ran=new Random(); int id=ran.nextInt(1000); int j=0; for(j=0;j<i;j++){ if(a[j]!=id) continue; else id=ran.nextInt(1000); } if(j==i){ a[i]=id; } this.id[i]=a[i]; suanshi=jisuandao.load(a[i]); suanshis.add(suanshi); i+=1; } return suanshis; } public int[] show(){ int[] num=new int[shu]; for(int i=0;i<shu;i++){ num[i]=id[i]; } return num; } public void adderr(Suanshi suanshi) { Connection connection = DBUtil.getConnection(); String sql ; PreparedStatement preparedStatement = null; ResultSet resultSet = null; sql = "insert into t_error(firstnum,operator,secondnum,result) values (?,?,?,?)"; try { preparedStatement = connection.prepareStatement(sql); String str=""; preparedStatement.setInt(1, suanshi.getFirstnum()); preparedStatement.setString(2, str+suanshi.getOperator()); preparedStatement.setInt(3, suanshi.getSecondnum()); preparedStatement.setInt(4, suanshi.getResult()); preparedStatement.executeUpdate(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { //关闭资源 DBUtil.close(resultSet); DBUtil.close(preparedStatement); DBUtil.close(connection); } } public List<Suanshi> loaderror() { // TODO Auto-generated method stub Connection connection = DBUtil.getConnection(); //准备sql语句 String sql = "select * from t_error "; //创建语句传输对象 PreparedStatement preparedStatement = null; ResultSet resultSet = null; //集合中只能放入user对象 List<Suanshi> suanshis = new ArrayList<Suanshi>(); Suanshi suanshi = null; try { preparedStatement = connection.prepareStatement(sql); resultSet = preparedStatement.executeQuery(); while(resultSet.next()) { suanshi = new Suanshi(); suanshi.setFirstnum(resultSet.getInt("firstnum")); suanshi.setSecondnum(resultSet.getInt("secondnum")); suanshi.setOperator(resultSet.getString("operator").charAt(0)); suanshi.setResult(resultSet.getInt("result")); suanshis.add(suanshi); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally { DBUtil.close(resultSet); DBUtil.close(preparedStatement); DBUtil.close(connection); } return suanshis; } }
package com.kao.msg.model; public class Suanshi { private int id; private int firstnum; private char operator; private int secondnum; private int result; private int useresult; public int getId() { return id; } public void setId(int id) { this.id = id; } public int getFirstnum() { return firstnum; } public void setFirstnum(int firstnum) { this.firstnum = firstnum; } public char getOperator() { return operator; } public void setOperator(char operator) { this.operator = operator; } public int getSecondnum() { return secondnum; } public void setSecondnum(int secondnum) { this.secondnum = secondnum; } public int getResult() { return result; } public void setResult(int result) { this.result = result; } public int getUseresult() { return useresult; } public void setUseresult(int useresult) { this.useresult = useresult; } }
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body background="D:娱乐电影1.jpg"> <div align="center"> <form action="Jisuan.jsp" method="get"> <table align="center" border="1" width="400"> <tr> <td align="center">请输入题目数量</td> <td align="center"> <input type="text" name="num" /> </td> </tr> <tr> <td align="center">请输入时间</td> <td align="center"> <input type="text" name="time" /> </td> </tr> <tr align="center"> <td colspan="2"> <input type="submit" value="确定" /> </td> </tr> </table> <a href="showerror.jsp">查看历史错题</a> </div> </form> </body> </html>
<%@page import="com.kao.msg.model.Suanshi"%> <%@page import="java.util.Scanner"%> <%@page import="java.util.Random"%> <%@page import="java.util.List"%> <%@page import="com.kao.msg.dao.JisuanDao"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>出题</title> </head> <body background="D:娱乐电影1.jpg"> <% String num = request.getParameter("num"); int usenum=Integer.parseInt(num); int time= Integer.parseInt(request.getParameter("time")); %> <% JisuanDao jisuandao=new JisuanDao(); List<Suanshi> suanshis= jisuandao.load1(usenum); %> <script type='text/javascript'> var num=<%=time%>; function calc(){ if(num>0){ num--; document.getElementById('second').innerHTML=num; }else{ document.forms[0].submit(); } setTimeout('calc()',1000); } </script> <body onload="calc()"> <div id='second'>5</div> </body> <div align="center"> <form action="tongji2.jsp" method="get"> <% int i=1; for( Suanshi suanshi : suanshis ){ %> <% out.print("第"+i+"题"); %> <%=suanshi.getFirstnum() %> <%=suanshi.getOperator() %> <%=suanshi.getSecondnum() %> <% %> =<input type="text" name="result" /> <% %> </br> </br> <% i+=1; } %> <head> <% %> <input type="submit" value="提交"/><br> </form> </div> </body> </html>
运行结果截图
时间记录日志
Personal Software Process Stages |
Time |
计划 |
|
· 估计这个任务需要多少时间 |
3个小时 |
开发 |
|
· 需求分析 (包括学习新技术) |
10分钟 |
· 生成设计文档 |
10分钟 |
· 设计复审 (和同事审核设计文档) |
无 |
· 代码规范 (为目前的开发制定合适的规范) |
10分钟 |
· 具体设计 |
10分钟 |
· 具体编码 |
1小时 |
· 代码复审 |
30分钟 |
· 测试(自我测试,修改代码,提交修改) |
2小时 |
报告 |
|
· 测试报告 |
无 |
· 计算工作量 |
无 |
· 事后总结, 并提出过程改进计划 |
1小时 |
合计 |
5小时10分钟 |
测试用例
(1)测试1个题目
(2)测试10个题目
(3)测试100个题目
(4)测试1000个题目
(5)测试10000个题目
(6)测试100000个题目
为的是测试出题上限是多少。
(7)不输入直接点提交测试
(8)输入负数测试
(9)输入字符串
(10)输入特殊字符
正确性
用户输入任何都不会导致报错,有足够健壮性