四则运算出题系统网页界面的实现(别期待,只有俩操作数)
index.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>主界面</title>
</head>
<body>
<center>
<form action="Ti1.jsp" method="post">
<table border="1">
<tr>
<td>请输入练习数目:</td>
<td><input type="text" name="count1" id="count1"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="开始" onclick="return check()"></td>
</tr>
</table>
</form>
</center>
<script>
function check(){
var count1=document.getElementById("count1").value;
if(count1==""){
alert("题目个数不能为空!");
return false;
}
}
</script>
</body>
</html>
Ti1.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>输入出题数目界面</title>
</head>
<body>
<%
int count1=Integer.parseInt(request.getParameter("count1"));
//int count2=Integer.parseInt(request.getParameter("count2"));
String[] values=new String[1000];//存储题目
int[] num=new int[1000];//存储计算机的正确结果
int[] results=new int[1000];//存储输入的结果
int i,j;
int a1,a2,a3;
String[] fu={"+","-","*","/"};
for(i=0;i<count1;){
int b1=0;
a1=(int)(Math.random()*100);
a2=(int)(Math.random()*100);
a3=(int)(Math.random()*4);
if(a3==0){//+
b1=a1+a2;
num[i]=b1;
values[i]=a1+"+"+a2+"=";
++i;
}
if(a3==1){//-
b1=a1-a2;
num[i]=b1;
values[i]=a1+"-"+a2+"=";
++i;
}
if(a3==2){//*
b1=a1*a2;
num[i]=b1;
values[i]=a1+"*"+a2+"=";
++i;
}
if(a3==3){// /
if(a2!=0){
b1=a1/a2;
num[i]=b1;
values[i]=a1+"+"+a2+"=";
++i;
}else{
continue;
}
}
}
%>
<center>
<form action="Ti2.jsp" method="post">
<table border="1">
<%
for(i=0;i<count1;i++){
%>
<tr>
<td><%=values[i]%></td>
<td><input type="hidden" name="values" value="<%=values[i]%>"></td>
<td><input type="text" name="results" ></td>
<td><input type="hidden" name="answer" value="<%=num[i]%>"></td>
<%
}
%>
</tr>
<tr>
<td></td>
<td><input type="submit" value="提交"></td>
</tr>
</table>
</form>
</center>
</body>
</html>
Ti2.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>做题结果界面</title>
</head>
<body>
<center>
<form>
<table border="1">
<%
String[] values=request.getParameterValues("values");//存储的题目
String[] results=request.getParameterValues("results");//输入框结果
String[] answer=request.getParameterValues("answer");//系统答案
int i;
int s1=0,s2=0,s3=0;
int sum=answer.length;//null?????
for(i=0;i<sum;i++){
if(results[i].equals("")){
s1++;
%>
<p><%=values[i]%> <%=results[i]%> <font color=red>答案未填写,正确答案为:</font><%=answer[i]%></p>
<%
}
else if(results[i].equals(answer[i])){
s2++;
%>
<p><%=values[i]%> <%=results[i]%> <font color=green>答案正确</font></p>
<%
}
else{
s3++;
%>
<p><%=values[i]%> <%=results[i]%> <font color=red>答案错误,正确答案为:</font><%=answer[i]%></p>
<%
}
}
%>
<tr>
<td>共做<font color=greed>对</font>题目:</td>
<td><%=s2%>道</td>
</tr>
<tr>
<td>共做<font color=red>错</font>题目:</td>
<td><%=s3%>道</td>
</tr>
<tr>
<td>有<font color=red>没做</font>的题目:</td>
<td><%=s1%>道</td>
</tr>
</table>
</form>
<a href="index.jsp">继续做题</a> <a href="Ti3.jsp">下次再来</a>
</center>
</body>
</html>
Ti3.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>结束做题界面</title>
</head>
<body>
<center>
<form>
<table border="1">
<tr>
<td><h1>结束啦!期待下次使用!</h1></td>
</tr>
</table>
</form>
</center>
</body>
</html>