四则运算2

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>出题数目</title>
</head>
<body>
<h1 style="font-family:Comic Sans MS;font-size:5em">欢迎小朋友们!</h1>
<body style="background:url(C:/Users/dell/Pictures/lovewallpaper/25140-106.jpg)">
<form action="dati.jsp" method="post">
<table align="center" border="0" width="500" style="margin:00px 200px 00px 5px">
<tr>
<td style="font-family:Comic Sans MS;font-size:2em;width:500px" align="right">想做几道题啊? </td>
<td>
<input style="width:100px;height:30px;" type="text" name="username" />
</td>
</tr>
<tr>
<td style="font-family:Comic Sans MS;font-size:2em;width:500px" align="right">想多长时间做完啊? </td>
<td>
<input style="width:100px;height:30px;" type="text" name="usertime" />
</td>
</tr>


<tr align="center">
<td colspan="2">
<input style="width:100px;height:30px; margin:00px 20px 00px 150px" type="submit" value="开始答题吧" />
</body>
</html>

 

 

<%@page import="com.jaovo.msg.model.Yunsuan"%>
<%@ page import="javax.swing.*" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head><title>出题页</title></head>
<body bgcolor=#FFE4C4 onload="load()">
<%
request.setCharacterEncoding("UTF-8");
String time = request.getParameter("usertime");
int time1=0;
int x=1;
for(int m=0;m<time.length();m++)
{
time1+=(time.charAt(time.length()-m-1)-'0')*x;
x*=10;
}
%>
<script>
var c=1;
var t;
var num1=<%=time1%>
function timeCount()
{
document.getElementById("txt").innerHTML=num1-c;
c=c+1;
t=setTimeout("timeCount()",1000);
if(num1==c-1)
{
clearTimeout(t);
alert("时间到了,小朋友休息一会儿吧!");
load();
}
}
function load(){
document.getElementById("anniu").click();
}
window.onload =function(){
timeCount();
}

</script>
<h1 style="font-family:Comic Sans MS;font-size:4em" >开始答题</h1>
<td style="font-family:Comic Sans MS;font-size:1em;width:500px" align="right">倒计时:</td>
<p id = "txt"></p>
<form action="jieguo.jsp" onsubmit="return validate()==1" method="get">
<%
request.setCharacterEncoding("UTF-8");
String num = request.getParameter("username");
int num1=0;
x=1;
for(int m=0;m<num.length();m++)
{
num1+=(num.charAt(num.length()-m-1)-'0')*x;
x*=10;
}
Yunsuan demo=new Yunsuan();
String []biaodashi1=new String[num1];
biaodashi1=demo.bds(num1);
demo.setss(biaodashi1);

for(int i=0;i<num1;i++)
{
out.println(biaodashi1[i]);
%>
<input style="width:80px;height:17px;align="right"" type="text" name="result[<%=i%>]"/> <!-- 答案输入文本框 -->
<%
out.println("<br/>");
out.println("<br/>");//换行
}
session.setAttribute("jieshou",demo);
%>
<tr>
<button id="anniu" onclick="test()" type="submit">提交</button>

</tr>
</body>
</html>

 

 

 

<%@page import="com.jaovo.msg.model.Yunsuan"%>
<%@ page import="javax.swing.*" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head><title>出题</title></head>

<body bgcolor=#FFE4C4>
<h1 style="font-family:Comic Sans MS;font-size:5em">正确答案</h1>
<%
Yunsuan nd=new Yunsuan();
nd=(Yunsuan)session.getAttribute("jieshou");
String []ys=new String[nd.num];
int sumrt=0,sumer=0,emp=0;
for(int i=0;i<nd.num;i++)
{
request.setCharacterEncoding("UTF-8");
out.print(nd.ss[i]);//正确的算式
ys[i] = request.getParameter("result["+i+"]");
out.println(ys[i]);
%>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<%
out.println("正确答案是: ");
out.println(nd.daan[i]);
%>
&nbsp;&nbsp;&nbsp;&nbsp;
<%
int num1=0;
int x=1;
for(int m=0;m<ys[i].length();m++)
{
num1+=(ys[i].charAt(ys[i].length()-m-1)-'0')*x;
x*=10;
}
if(ys[i].equals(""))
{
out.println("你没有回答哦!");
emp++;
}
else if(num1==nd.daan[i])
{
sumrt++;
out.println("恭喜你!回答正确!");
}
else
{
sumer++;
out.println("回答错误,再接再厉!");
}
out.println("<br/>");
}
out.println("回答正确了"+sumrt+"道题!");
out.println("<br/>");
out.println("回答错误了"+sumer+"道题!");
out.println("<br/>");
out.println("没有回答"+emp+"道题!");
out.println("<br/>");
%>
</tr>
<a href="huanying.jsp">退出</a>
</body>
</html>

 

 

package com.jaovo.msg.model;

public class Yunsuan{
public int []daan;
public int num;
public String []ss;
public void setss(String []ss)
{
this.ss=ss;
}
public String [] bds(int n)
{
num=n;
daan=new int[n];
int a,b,c,d1 = 0,d,d2=0;
int []ydy=new int[2];
String []bds=new String[n];
for(int i=0;i<n;i++)
{
a=(int)(Math.random()*100)+1;
b=(int)(Math.random()*100)+1;
c=(int)(Math.random()*5)+1;
if(c==1)//减法
{
d1=a-b;
while(d1<0)
{
a=(int)(Math.random()*100)+1;
b=(int)(Math.random()*100)+1;
d1=a-b;
}
bds[i]=a+"-"+b+" = ";
daan[i]=d1;
System.out.print(a+"-"+b+"= ");
}
if(c==2)//乘法
{
a=(int)(Math.random()*10);//0-9
b=(int)(Math.random()*10);//1-100 包括1和100 不加1 表示0-99
d1=a*b;
while(a<1||b<1||d1>81)
{
a=(int)(Math.random()*10);//0-9
b=(int)(Math.random()*10);//1-100 包括1和100 不加1 表示0-99
}
d1=a*b;
bds[i]=a+"*"+b+" = ";
daan[i]=d1;
System.out.print(a+"*"+b+"= ");
}
if(c==3)//除法
{
d1=a/b;
while(a%b!=0||a/b>9||(a<=81&&b>=10)||(a>9&&a==b)||(a>81))
{
a=(int)(Math.random()*100)+1;
b=(int)(Math.random()*100)+1;//1-100 包括1和100 不加1 表示0-99
}
d1=a/b;
bds[i]=a+"÷"+b+" = ";
daan[i]=d1;
System.out.print(a+"÷"+b+"= ");
}
if(c==4)//加法
{
d1=a+b;
bds[i]=a+"+"+b+" = ";
while(d1>100)
{
a=(int)(Math.random()*100)+1;
b=(int)(Math.random()*100)+1;//1-100 包括1和100 不加1 表示0-99
d1=a+b;
}
bds[i]=a+"+"+b+" = ";
daan[i]=d1;
System.out.print(a+"+"+b+"= ");
}
if(c==5)//混合运算
{
do
{
for(int m=0;m<2;m++)
{
ydy[m]=(int)(Math.random()*2);//0-1
}//控制运算符
a=(int)(Math.random()*100)+1;
b=(int)(Math.random()*100)+1;
d=(int)(Math.random()*100)+1;//生成三个数
if(ydy[0]==0&&ydy[1]==0)
{
bds[i]=a+"+"+b+"+"+d+" = ";
d1=a+b+d;
}
if(ydy[0]==1&&ydy[1]==1)
{
bds[i]=a+"-"+b+"-"+d+" = ";
d2=a-b;
d1=a-b-d;
}
if(ydy[0]==0&&ydy[1]==1)
{
bds[i]=a+"+"+b+"-"+d+" = ";
d1=a+b-d;
}
if(ydy[0]==1&&ydy[1]==0)
{
bds[i]=a+"-"+b+"+"+d+" = ";
d2=a-b;
d1=a-b+d;
}
} while(d2<0||d1<0);
daan[i]=d1;
}

//查重
for(int k=i-1;k>=0;k--)
{
while(bds[i].equals(bds[k]))
{
a=(int)(Math.random()*100)+1;//1-100
b=(int)(Math.random()*100)+1;
c=(int)(Math.random()*5)+1;//随机生成一个1-5的整数,4表示加法,1表示减法,2表示乘法,3表示除法,5表示混合


if(c==1)
{
d1=a-b;
while(d1<0)
{
a=(int)(Math.random()*100)+1;
b=(int)(Math.random()*100)+1;
d1=a-b;
}
bds[i]=a+"-"+b+" = ";
daan[i]=d1;
System.out.print(a+"-"+b+"= ");
}
if(c==2)
{
a=(int)(Math.random()*10);//0-9
b=(int)(Math.random()*10);//1-100 包括1和100 不加1 表示0-99
d1=a*b;
while(a<1||b<1||d1>81)
{
a=(int)(Math.random()*10);//0-9
b=(int)(Math.random()*10);//1-100 包括1和100 不加1 表示0-99
}
d1=a*b;
bds[i]=a+"*"+b+" = ";
daan[i]=d1;
System.out.print(a+"*"+b+"= ");
}
if(c==3)
{
while(a%b!=0)
{
a=(int)(Math.random()*100)+1;
b=(int)(Math.random()*100)+1;//1-100 包括1和100 不加1 表示0-99
}
d1=a/b;
bds[i]=a+"÷"+b+" = ";
daan[i]=d1;
System.out.print(a+"÷"+b+"= ");
}
if(c==4)
{
d1=a+b;
bds[i]=a+"+"+b+" = ";
while(d1>100)
{
a=(int)(Math.random()*100)+1;
b=(int)(Math.random()*100)+1;//1-100 包括1和100 不加1 表示0-99
d1=a+b;
}
bds[i]=a+"+"+b+" = ";
daan[i]=d1;
System.out.print(a+"+"+b+"= ");
}
if(c==5)
{
do//混合运算
{
for(int m=0;m<2;m++)
{
ydy[m]=(int)(Math.random()*2);//0-1
}//控制运算符

a=(int)(Math.random()*100)+1;
b=(int)(Math.random()*100)+1;
d=(int)(Math.random()*100)+1;//生成三个数
if(ydy[0]==0&&ydy[1]==0)
{
bds[i]=a+"+"+b+"+"+d+" = ";
d1=a+b+d;
}
if(ydy[0]==1&&ydy[1]==1)
{
bds[i]=a+"-"+b+"-"+d+" = ";
d2=a-b;
d1=a-b-d;
}
if(ydy[0]==0&&ydy[1]==1)
{
bds[i]=a+"+"+b+"-"+d+" = ";
d1=a+b-d;
}
if(ydy[0]==1&&ydy[1]==0)
{
bds[i]=a+"-"+b+"+"+d+" = ";
d2=a-b;
d1=a-b+d;
}
}while(d2<0||d1<0);
daan[i]=d1;
}
}
}
}
return bds;
}
}

设计思想:写好随机生成四则运算然后有jsp相互跳转

psp0级:

项目计划总结:

时间记录日志:

 

缺陷记录日志:

细节地方还是很欠缺。

posted @ 2017-12-06 19:07  胖虎ydy  阅读(192)  评论(1编辑  收藏  举报