四则运算自动出题系统——网页版

第一个界面:输入题目总数和每行要显示的题目数

第二个界面:答题界面

第三个界面:判错界面,可选择重新回到第一个界面或进入第四个界面

第四个界面:结束界面

 

 

源码:

1.si.jsp

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html>
 4 <html>
 5 <head>
 6 <meta charset="UTF-8">
 7 <h2>四则运算自动出题系统</h2>
 8 <style type="text/css">
 9 .big{
10 position:absolute;
11 left:50%;
12 margin-left:-100px;
13 top:50%;
14 margin-top:-200px;
15 }
16 </style>
17 </head>
18 
19 
20 <body   text="Black"  style="background: ; background-size:100%">
21 <div align="center">
22 <form action="ze.jsp" method="post"  onsubmit="return checkall()">
23 <table>
24     <tr>
25     <td>题目总数</td>
26     <td>
27      <input type="text" name="number1" id="number1" value=""  placeholder="请输入"  onchange="check1()"/>
28     </td>
29     </tr>
30     <tr>
31     <td>每行的题目个数</td>
32     <td><input type="text" name="number2" id="number2"  value="" placeholder="请输入" onchange="check2()" /></td>
33     </tr>
34     <tr>
35       <td><input type="submit"  value="开始答题"></td>
36   </tr>
37     
38 </table>
39 
40 </form>
41 <script type="text/javascript">
42     
43     function check1()
44     {
45         var number1=document.getElementById("number1");
46         var num=number1.value;
47         if(num=="")
48         {
49             alert('总数不能为空');
50             number1.focus();
51             return false;
52         }
53     }
54     
55     function check2()
56     {
57         var number2 = document.getElementById("number2");
58         var num2=number2.value;
59         if(num2=="")
60         {
61             alert('行数不能为空');
62             number1.focus();
63             return false;
64         }
65     }
66     function checkall()
67     {
68         var num1=document.getElementById("number1");
69         var number1=num1.value;
70         var num2 = document.getElementById("number2");
71         var number2=num2.value;
72         if(number1=="")
73         {
74             alert('总数不能为空');
75             num1.focus();
76             return false;
77         }
78         if(number2=="")
79         {
80             alert('行数不能为空');
81             num2.focus();
82             return false;
83         }
84         
85     }
86     </script>
87       </div>
88 </body>
89 
90 </html>

 

 

 

2.ze.jsp

  1 <%@ page language="java" contentType="text/html; charset=UTF-8"
  2     pageEncoding="UTF-8"%>
  3 <!DOCTYPE html>
  4 <html>
  5 <head>
  6 <meta charset="UTF-8">
  7 <%
  8 int s1= Integer.parseInt(request.getParameter("number1"));
  9 int s2 = Integer.parseInt(request.getParameter("number2"));
 10 String value[]=new String[s1];
 11 int num[]=new int[s1];
 12 int a1,a2,a3;
 13 int b1,b2,b3;
 14 int s3[]=new int[100];
 15 int s4[]=new int[100];
 16 int s5[]=new int[100];
 17 int s6[]=new int[100];
 18 int s7[]=new int[100];
 19 int s8[]=new int[100];
 20 int s9[]=new int[100];
 21 int s10[]=new int[100];
 22 char fuhao[]= {'+','-','*','/'};
 23 nn:for(a1=1;a1<=s1;)
 24 {
 25     for(a2=1;a2<=s2;)
 26     {
 27         b1=(int)(Math.random()*100);
 28         b2=(int)(Math.random()*100);
 29         b3=(int)(Math.random()*4);
 30         if(b3==0)
 31         {
 32             if(s3[b1]==1)
 33             {
 34                 if(s4[b2]==1)
 35                 {
 36                     continue;
 37                 }
 38                 else
 39                 {
 40                     s3[b1]=1;
 41                     s4[b2]=1;
 42                     a3=b1+b2;
 43                     num[a1-1]=a3;
 44                     value[a1-1]=b1+"+"+b2;
 45                 }
 46             }
 47             else
 48             {
 49                 s3[b1]=1;
 50                 s4[b2]=1;
 51                 a3=b1+b2;
 52                 num[a1-1]=a3;
 53                 value[a1-1]=b1+"+"+b2;
 54             }
 55         }
 56         if(b3==1)
 57         {
 58             if(b1>=b2)
 59             {
 60                 if(s5[b1]==1)
 61                 {
 62                     if(s6[b2]==1)
 63                     {
 64                         continue;
 65                     }
 66                     else
 67                     {
 68                         s5[b1]=1;
 69                         s6[b2]=1;
 70                         a3=b1-b2;
 71                         num[a1-1]=a3;
 72                         value[a1-1]=b1+"-"+b2;
 73                     }
 74                 }
 75                 else
 76                 {
 77                     s5[b1]=1;
 78                     s6[b2]=1;
 79                     a3=b1-b2;
 80                     num[a1-1]=a3;
 81                     value[a1-1]=b1+"-"+b2;
 82                 }
 83             }
 84             else
 85                 continue;
 86         }
 87         if(b3==2)
 88         {
 89             if((b1*b2)/100==0)
 90             {
 91                 if(s7[b1]==1)
 92                 {
 93                     if(s8[b2]==1)
 94                     {
 95                         continue;
 96                     }
 97                     else
 98                     {
 99                         s7[b1]=1;
100                         s8[b2]=1;
101                         a3=b1*b2;
102                         num[a1-1]=a3;
103                         value[a1-1]=b1+"*"+b2;
104                     }
105                 }
106                 else
107                 {
108                     s7[b1]=1;
109                     s8[b2]=1;
110                     a3=b1*b2;
111                     num[a1-1]=a3;
112                     value[a1-1]=b1+"*"+b2;
113                 }
114             }
115             else
116                 continue;
117         }
118         if(b3==3)
119         {
120             if(b2!=0&&b1%b2!=0)
121             {
122                 continue;
123             }
124             if(b2==0)
125             {
126                 continue;
127             }
128             if(s9[b1]==1)
129             {
130                 if(s10[b2]==1)
131                 {
132                     continue;
133                 }
134                 else
135                 {
136                     s9[b1]=1;
137                     s10[b2]=1;
138                     a3=b1/b2;
139                     num[a1-1]=a3;
140                     value[a1-1]=b1+"/"+b2;
141                 }
142             }
143             else
144             {
145                 s9[b1]=1;
146                 s10[b2]=1;
147                 a3=b1/b2;
148                 num[a1-1]=a3;
149                 value[a1-1]=b1+"/"+b2;
150             }
151         }
152         if(a1==s1)
153         {
154             break nn;
155         }
156         ++a1;
157         ++a2;
158     }
159 }
160 %>
161 <title>Insert title here</title>
162 </head>
163 <body    style="background:  ;background-size:100%">
164 <div align="center">
165 <form action="yun.jsp">
166 <h2>请作答:</h2>
167 <table>
168   <%
169     mm:for(int j=0;j<s1;){
170      %>
171      <tr>
172      <%for(int j1=0;j1<s2;)
173          {%>
174 
175    <td><%=value[j] %>=</td>
176    <td><input type="hidden" name="values" value=<%=value[j]%>></td>
177    <td><input type="text" name="result" value=""></td>
178    <td><input type="hidden" name="answer" value=<%=num[j] %>></td>
179   <% 
180   j++;
181   j1++;
182   if(j==s1)
183       {
184       break mm;
185       }
186       }
187     %>
188     </tr>
189   <% 
190     }
191     %>
192     <tr>
193     <td>
194     <input type="submit" value="提交">
195     </td>
196     </tr>
197     </table>
198  </form>
199      </div>
200 </body>
201 </html>

 

 

 

 

3.yun.jsp

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html>
 4 <html>
 5 <head>
 6 <meta charset="UTF-8">
 7 <title>Insert title here</title>
 8 </head>
 9 <body  text="Black"  style="background: ; background-size:100%">
10 <div align="center">
11 <%
12 String result[] = request.getParameterValues("result");
13 String sum[] = request.getParameterValues("answer");
14 String values[] = request.getParameterValues("values");
15 int q1=sum.length;
16 int s1=0,s2=0,s3=0;
17 for(int q3=0;q3<q1;q3++)
18 {
19     if(result[q3].equals(""))
20     {
21         s1++;
22         %>
23         <p><%=values[q3]%>=<%=result[q3]  %><font color="red">没有填写,正确答案为</font><%=sum[q3] %></p>
24         <%
25     }
26     
27     else if(result[q3].equals(sum[q3]))
28     {
29         s2++;
30         %>
31         <p><%=values[q3]%>=<%=result[q3]  %><font color="green">答案正确</font></p>
32         <%
33     }
34     else 
35     {
36         s3++;
37         %>
38         <p><%=values[q3]%>=<%=result[q3]  %><font color="red">答案错误,正确答案为</font><%=sum[q3] %></p>
39         <%
40     }
41 }
42 %>
43 
44 <h2>
45    你答对了<%=s2   %>题,答错了<%=s3  %>题,没有答<%=s1  %>题。
46 </h2>
47 <a href="si.jsp"><button>新的题目</button></a>
48   <a href="suan.jsp"><button>结束做题</button></a>
49   </div>
50 </body>
51 </html>

 

 

 

4.suan.jsp

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html>
 4 <html>
 5 <head>
 6 <meta charset="UTF-8">
 7 <title>Insert title here</title>
 8 </head>
 9 <body  text="Pink" style="font-size:300px;" >
10 <p align="center">Over</p>
11 </body>
12 </html>

 

 

 

 

 

  效果图  

 

 

 

 

 

 

 

 

 

 

 

posted @ 2019-11-03 14:57  _Aming  阅读(575)  评论(0编辑  收藏  举报