四则运算出题机之JAVAWEB版
要求还是和之前的出题形式一样
begin.jpg
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>选择题数页面</title>
</head>
<body style="background: url(images/1.jpg); background-size:100%">
<form name="form1" action="chuti.jsp" onsubmit="return check(form1);">
<h2 align="center">四则运算自动出题机</h2>
<table align="center">
<tr>
<td>题数</td>
<td><input type="text" name="number" value="" placeholder="请输入题数" onchange="checkti(form1)"></td>
</tr>
<tr>
<td>每行个数</td>
<td><input type="text" name="hang" value="" placeholder="请输入每行输出几个" onchange="checkhang(form1)"></td>
</tr>
<tr>
<td><input type="submit" value="提交"></td>
</tr>
</table>
<script type="text/javascript">
function check(form1)
{
var num = form1.number.value;
var hang=form1.hang.value;
if(num.length==0)
{
alert("题数不能为空");
form1.number.value="";
form1.number.focus();
return false;
}
if(hang.length==0)
{
alert("每行个数不为空");
form1.hang.value="";
form1.hang.focus();
return false;
}
}
function checkti(form1)
{
var num = form1.number.value;
if(num=="")
{
alert("题数不能为空");
form1.number.value="";
form1.number.focus();
return false;
}
}
function checkhang(form1)
{
var hang=form1.hang.value;
if(hang.length==0)
{
alert("每行个数不为空");
form1.hang.value="";
form1.hang.focus();
return false;
}
}
</script>
</form>
</body>
</html>
chuti.jpg
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>出题界面</title>
</head>
<body style="background: url(images/2.jpg); background-size:100%">
<%
int h=Integer.parseInt(request.getParameter("hang"));
int x=Integer.parseInt(request.getParameter("number"));
String value[]=new String[x];
String answer[]=new String[x];
int i;
for(i=0;i<x;)
{
int num1=(int)(1+(Math.random()*100));
int num2=(int)(1+(Math.random()*100));
int f=(int)(1+(Math.random()*4));
if(f==1)
{
value[i]=num1+"+"+num2+"=";
answer[i]=num1+num2+"";
i++;
}
else if(f==2&&num1>=num2)
{
value[i]=num1+"-"+num2+"=";
answer[i]=num1-num2+"";
i++;
}
else if(f==3&&num1*num2<100)
{
value[i]=num1+"*"+num2+"=";
answer[i]=num1*num2+"";
i++;
}
else if(f==4&&num2!=0&&num1%num2==0)
{
value[i]=num1+"/"+num2+"=";
answer[i]=num1/num2+"";
i++;
}
else
continue;
}
%>
<h2 align="center">练习题</h2>
<form action="panduan.jsp">
<table align="center">
<%
int k;
for(int j=0;j<x;)
{
k=0;
%>
<tr>
<%
while(k<h)
{
%>
<td><%=value[j] %></td>
<td><input type="hidden" name="value" value=<%=value[j] %>></td>
<td><input type="text" name="result" /></td>
<td><input type="hidden" name="answer" value=<%=answer[j] %>></td>
<%
j++;
k++;
if(j>=x)
break;
}
%>
</tr>
<%
}
%>
<tr>
<td><input type="submit" value="提交"></td>
</tr>
</table>
</form>
</body>
</html>
panduan.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>判断对错</title>
</head>
<body text="red" style="background: url(images/3.jpg); background-size:100%">
<%
int a=0,b=0,c=0,i,k=0;
String result[]=request.getParameterValues("result");
String answer[]=request.getParameterValues("answer");
String values[]=request.getParameterValues("value");
for(i=0;i<values.length;i++)
{
values[i]+=result[i];
if(result[i].equals(""))
{
%>
<p align="center"><%=values[i] %>,该题没有填写,正确答案为<%=answer[i] %></p>
<%
a++;
}
else if(result[i].equals(answer[i]))
{
%>
<p align="center"><%=values[i] %>,回答正确。</p>
<%
b++;
}
else
{
%>
<p align="center"><%=values[i] %>,回答错误,正确答案为<%=answer[i] %></p>
<%
c++;
}
}
%>
<h2 align="center">总共<%=values.length %>道题,回答正确<%=b %>道,回答错误<%=c %>道,没有作答<%=a %>道。</h2>
<p align="center" ><a href="begin.jsp">重新做答</a></p>
<p align="center" ><a href="jieshu.jsp">结束</a></p>
</body>
</html>
jieshu.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>结束界面</title>
</head>
<body style="background: url(images/4.jpg); background-size:100%">
<h1 align="center">结束</h1>
</body>
</html>
流程截图
这就是javaweb版的四则运算出题机。