问题:
把程序变成一个网页程序,用户通过设定参数,就可以得到各种题目,并可实现在线答题并评判。
撰写一篇博文要求将程序的设计思想,源程序代码、运行结果截图以及编程总结或体会,博客标题:软件工程结对作业01;
在开始实现程序之前,使用下述PSP表格记录下你估计将在程序的各个模块的开发上耗费的时间。
在你实现完程序之后,使用下述PSP表格记录下你在程序的各个模块上实际花费的时间。
1.设计思想设计两个选择界面,第一个界面的选择内容对第二个界面有关系,影响第二个界面。把选择界面的选择结果传递到答题文件内的变量里面,把限制条件控制好生成满足需要的结果,把题目输出经过答题后,将结果与实际结果比较,判断对错。统计答题正确的个数。
2.源程序:
(1)选择界面1
<%@ 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> <style type="text/css"> body { background-image: url(images/7.jpg); } </style> </head> <body> <form action="Luru2.jsp" method="post" name="form1" id="form1"> <p> </p> <p> </p> <center> <p style="color: #09F; font-size: 36px;"><strong>四则运算答题系统</strong></p> <p> </p> <p> 是否含有分数: <input type="radio" name="fenshu" value="0"/> 有 <input type="radio" name="fenshu" value="1"/>无 </p> <p> 是否有除法: <input type="radio" name="ifchu" value="0"/>有 <input type="radio" name="ifchu" value="1"/>无 </p> </center> <p> </p> <p> <center><input type="submit" value="下一步" class="submit_btn"/></center> </p> </form> </body> </html>
(2)选择界面2
<%@ 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> <style type="text/css"> body { background-image: url(images/2.jpg); } </style> </head> <body> <form action="createAndjh.jsp" method="post" name="form1" id="form1"> <p> </p> <h1><p><strong><center><span style="color=:#09F; ">四则运算答题系统</center></strong></span> </p></h1> <p> </p> <p> <table align=center width=500 border=1> <tr><td><center><strong>选项</strong></center> <% String fenshu = request.getParameter("fenshu"); session.setAttribute("fenshu",fenshu); String ifchu = request.getParameter("ifchu"); session.setAttribute("ifchu",ifchu); //out.print("<tr><td>"+"请输入算数的个数::"+"<input type='text' name='canshu'><br/></td>"); out.print("<tr><td>"+"请输入题目的个数::"+"<input type='text' name='geshu'><br/></td>"); if(fenshu.equals("0")) { out.print("<tr><td>"+"请输入分母的生成范围<br/>"+"最小值:<input type='text' name='min'><br/>最大值:<input type='text' name='max'><br/>"); } else if(fenshu.equals("1")) { out.print("<tr><td>"+"请输入整数的生成范围<br/>"+"最小值:<input type='text' name='min'><br/>最大值:<input type='text' name='max'><br/>"); } if(ifchu.equals("0")) { out.print("<tr><td>"+"除法是否有余数:<input type='radio' name='ifyu' value='0'/>有 <input type='radio' name='ifyu' value='1'/>无<br/>"); } out.print("<tr><td>"+"是否有负数:<input type='radio' name='iffu' value='0'/>有 <input type='radio' name='iffu' value='1'/>无<br/>"); out.print("<tr><td>"+"是否有括号:<input type='radio' name='ifkuo' value='0'/>有<input type='radio' name='ifkuo' value='1'/>无<br/>"); %> <center><input type="submit" value="下一步" class="submit_btn"/></center> </p> </form> </body> </html>
(3)答题界面:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@page import="demo.*"%> <!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> <style type="text/css"> body { background-image: url(images/4.jpg); } </style> </head> <body> <p> <% String fenshu = session.getAttribute("fenshu").toString(); String ifchu = session.getAttribute("ifchu").toString(); String min = request.getParameter("min"); String max = request.getParameter("max"); int cy=2; if(ifchu.equals("0")) { String ifyu = request.getParameter("ifyu"); session.setAttribute("ifyu",ifyu); cy=Integer.parseInt(ifyu); } String iffu = request.getParameter("iffu"); String ifkuo = request.getParameter("ifkuo"); String geshu = request.getParameter("geshu"); //String canshu = request.getParameter("canshu"); session.setAttribute("min",min); session.setAttribute("max",max); session.setAttribute("ifkuo",ifkuo); session.setAttribute("geshu",geshu); //session.setAttribute("fcanshu",canshu); int d1=Integer.parseInt(min); int d2=Integer.parseInt(max); //int n=Integer.parseInt(canshu); int num=Integer.parseInt(geshu); int f=Integer.parseInt(fenshu); int cc=Integer.parseInt(ifchu); int jf=Integer.parseInt(iffu); int kh=Integer.parseInt(ifkuo); Test test=new Test(); String[] shizi=new String[num]; String[] stuanswer=new String[num]; test.createAndoutput(f, d1, d2, cc, jf, kh, num, cy, shizi,stuanswer); %> <tr><td><center><strong>请认真答题</strong></center> </p> <!-- <p style="color:#FF0">题组如下(注负假分数格式:-1'2/5) ,请仔细答题:</p>- --> <form action="calculate.jsp" method="post" name="form1" id="form1"> <table align="center" width="98%" border="1" cellpadding="1" cellspacing="1"> <tr> <td width="40" align="center">序号</td> <td width="200" align="center">题目</td> </tr> <% String[] answerhao=new String[num]; String[] tihao=new String[num]; for(int i=0;i<num;i++) { answerhao[i]="answer"+i; tihao[i]="question"+i; session.setAttribute(answerhao[i],stuanswer[i]); session.setAttribute(tihao[i],shizi[i]); out.print("<tr><td align='center'>"+(i+1)+"</td><td align='center'>"+shizi[i]+"<input type='text' name='"+answerhao[i]+"' ></td>"); } %> <tr> <td height="40" align="center"> </td> <td><label> <center><input type="submit" name="Submit" value="上传" /></center> </label></td> </tr> </table> </form> </body> </html>
(4)结果界面:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@page import="demo.*"%> <!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> <style type="text/css"> body { background-image: url(images/4.jpg); } </style> </head> <body> <p> </p> <p> <% String geshu = session.getAttribute("geshu").toString(); int num=Integer.parseInt(geshu); String[] answer=new String[num]; String[] stuanswer=new String[num]; String[] answerhao=new String[num]; for(int i=0;i<num;i++) { answerhao[i]="answer"+i; answer[i]=request.getParameter(answerhao[i]); answer[i]=answer[i].replaceAll("â","'"); stuanswer[i]=session.getAttribute(answerhao[i]).toString(); stuanswer[i]=stuanswer[i].replaceAll("‘","'"); } Test test=new Test(); out.print("您的做题详细情况:<br />"); %> <table align="center" width="98%" border="1" cellpadding="1" cellspacing="1"> <tr> <td width="70" align="center">序号</td> <td width="458" align="center">题目</td> <td width="168" align="center">详情</td> </tr> <% String[] shizi=new String[num]; String[] tihao=new String[num]; for(int i=0;i<num;i++) { tihao[i]="question"+i; shizi[i]=session.getAttribute(tihao[i]).toString(); if(answer[i].equals(stuanswer[i])) { out.print("<tr><td align='center'>"+(i+1)+"</td><td align='center'>"+shizi[i]+" "+answer[i]+"</td><td align='center'>√</td></tr>"); } else out.print("<tr><td align='center'>"+(i+1)+"</td><td align='center'>"+shizi[i]+" "+answer[i]+"</td><td align='center'>× 正确答案:"+stuanswer[i]+"</td></tr>"); } String xiangqing=test.testanswer(answer, stuanswer, num); out.print(xiangqing+"<br />"); %> </table> </p> <p> </p> <p> </p> </body> </html>
截图:
选择界面1:
选择界面2
答题界面:
评分界面:
4.总结
实验基本上完成了,一些基本要求实现了,但是并不全面,还有一些没有实现,现在只能考虑余数、负数、括号,范围,不能控制题目中变量的个数。