标签:
1》设计思路
1.首先编写一个input.jsp页面,用于输入各种参数,如出题的个数和数值上限,简单运算还是混合运算
1 <%@ page language="java" contentType="text/html; charset=utf-8" 2 pageEncoding="utf-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 7 <title>首页</title> 8 </head> 9 <body background="image/beijing1.jpg"> 10 <form name="form1" method="post"action="index.jsp"> 11 <center>小学生的四则运算</center> 12 <table align="center"> 13 <tr> 14 <td> 请输入要出题的题目数量: </td> 15 <td> <input name="shuliang" type="text" id="shuliang"maxlength="5"></td> 16 </tr> 17 <tr> 18 <td> 19 请输入要出题范围(1~?): 20 </td> 21 <td> 22 <input name="fanwei" type="text" id="fanwei"maxlength="5"> 23 </td> 24 </tr> 25 <tr> 26 <td>请选择计算的类型: 27 </td> 28 <td> 29 <select name="leixing"> 30 <option value=0>简单运算</option> 31 <option value=1>混合运算</option> 32 </select> 33 </td> 34 </tr> 35 </table> 36 <center><input type="submit"value="开始答题"></center> 37 </form> 38 </body> 39 </html>
index.jsp
1 <%@ page language="java" contentType="text/html; charset=utf-8" 2 pageEncoding="utf-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 7 <title>首页</title> 8 </head> 9 <body background="image/beijing1.jpg"> 10 <form name="form1" method="post"action="index.jsp"> 11 <center>小学生的四则运算</center> 12 <table align="center"> 13 <tr> 14 <td> 请输入要出题的题目数量: </td> 15 <td> <input name="shuliang" type="text" id="shuliang"maxlength="5"></td> 16 </tr> 17 <tr> 18 <td> 19 请输入要出题范围(1~?): 20 </td> 21 <td> 22 <input name="fanwei" type="text" id="fanwei"maxlength="5"> 23 </td> 24 </tr> 25 <tr> 26 <td>请选择计算的类型: 27 </td> 28 <td> 29 <select name="leixing"> 30 <option value=0>简单运算</option> 31 <option value=1>混合运算</option> 32 </select> 33 </td> 34 </tr> 35 </table> 36 <center><input type="submit"value="开始答题"></center> 37 </form> 38 </body> 39 </html>
Result.jsp
1 <%@ page language="java" contentType="text/html; charset=utf-8" 2 pageEncoding="utf-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 7 <title>结果</title> 8 </head> 9 <body background="image/beijing3.jpg"> 10 <% 11 String[] s= (String[])session.getAttribute("v1"); 12 String[] answer= (String[])session.getAttribute("v2"); 13 String[] daan=new String[s.length]; 14 int count=0;//正确答案的个数 15 for(int i=0;i<s.length;i++) 16 { 17 out.print("运算式为:"); 18 out.print(s[i]+" "); 19 out.print("您的输入结果为:"); 20 daan[i]=request.getParameter("name"+i); 21 out.print(daan[i]+" "); 22 out.print("正确结果为:"); 23 out.print(answer[i]); 24 if(Integer.parseInt(daan[i])==Integer.parseInt(answer[i])) 25 { 26 out.print("恭喜你答对了!"); 27 count++; 28 } 29 else 30 { 31 out.print("很遗憾,你打错了!"); 32 } 33 out.print("<br>"); 34 } 35 out.print("你一共答对的题目数:"); 36 out.print(count); 37 %> 38 </body> 39 </html>
3》结果截图:
总结:因为时间的因素,还有对知识掌握的还不太熟练,所以一些功能还没实现,不过我课下会积极努力完成功能,进行完善,这只是初期版
标签:
原文地址:http://www.cnblogs.com/sz20142898/p/5384661.html