一、设计思路
上次基本上已经差不多了,这次主要写带括号及分数的运算,解决了一大难点,也是一个核心步骤。
二、源代码
首页:
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=ISO-8859-1"> 7 <title>自动出题</title> 8 </head> 9 10 <body style="background: url(image/backImage.jpg)"> 11 <form action="Ct" method="post"> 12 <center> 13 <h2>自动出题</h2> 14 <h3>出题类型:<input type="radio" name="type" value="zhengshu">整数 15 <input type="radio" name="type" value="zhenfenshu">真分数 16 <input type="radio" name="type" value="douyou">都有<br> 17 乘除法:<input type="radio" name="chengchu" value="1">有 18 <input type="radio" name="chengchu" value="0">无<br> 19 括号:<input type="radio" name="kuohao" value="1">有 20 <input type="radio" name="kuohao" value="0">无<br> 21 出题范围:0到<input type="text" name ="fanwei" ><br> 22 参与计算数:<input type="text" name ="num" ><br> 23 出题数:<input type="text" name ="chutishu" ><br> 24 结果有无余数:<input type="radio" name="yushu" value="1">有 25 <input type="radio" name="yushu" value="0">无(二元运算)<br> 26 结果有无负数:<input type="radio" name="fushu" value="1">有 27 <input type="radio" name="fushu" value="0">无<br> 28 </h3> 29 <input type="submit" value="出题"> 30 31 </center> 32 </form> 33 34 35 36 </body> 37 </html>
出题界面:
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=ISO-8859-1"> 7 <title>自动出题</title> 8 </head> 9 10 <body style="background: url(image/backImage.jpg)"> 11 <% 12 int chutishu=(int)request.getAttribute("chutishu"); 13 String[] timu=(String[])request.getAttribute("timu"); 14 String[] daan=(String[])request.getAttribute("daan"); 15 JspWriter mout=pageContext.getOut(); 16 %> 17 <center><form action="jieguo.jsp" method="post"> 18 <% for(int i=0;i<chutishu;i++){ 19 mout.print((i+1)+". "+timu[i]+"<br>"); 20 %> 21 <input type="text" name ="<%=i%>" ><br> 22 <%} 23 session.setAttribute("chutishu", chutishu); 24 session.setAttribute("daan", daan); 25 session.setAttribute("timu", timu); 26 %> 27 <input type="submit" value="提交"> 28 </form> </center> 29 30 31 </body> 32 </html>
显示答案界面:
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=ISO-8859-1"> 7 <title>答案</title> 8 </head> 9 <body style="background: url(image/backImage.jpg)"> 10 <% 11 int chutishu=(int)session.getAttribute("chutishu"); 12 String[] daan=(String[])session.getAttribute("daan"); 13 String[] timu=(String[])session.getAttribute("timu"); 14 int t=0,f=0; 15 JspWriter mout=pageContext.getOut(); 16 for(int i=0;i<chutishu;i++){ 17 String s=request.getParameter(""+i+""); 18 mout.print(i+1+"."+timu[i]);%> <% 19 mout.print("你的答案:"+s);%> <% 20 mout.print("正确答案:"+daan[i]);%> <% 21 //判断正误及计数 22 if(s.equals(daan[i])||(s+".0").equals(daan[i])) 23 {t++;%> <%mout.print("√<br><br>");} 24 else 25 {f++;%> <%mout.print("×<br><br>");} 26 27 } 28 %> <%mout.print("共"+chutishu+"道题");%> <% 29 mout.print("对:"+t);%> <% 30 mout.print("错:"+f); 31 %> 32 </body> 33 </html>
三、截图