1.设计思路:

定义一个类arithmetic,在该类中的定义相关成员,随机产生的题目以及答案用数组承接,在第一个jsp里面用户输入题目数量以及设置做题时间,将这两个数传到第二个jsp页面,在此页面定义类对象,调用相关类函数,进行出题:

最后将算式的数组和答案的数组以及用户输入的值传到第三个jsp页面,进行答案的校对即可。

源代码:

arithmetic.java:

package com.jaovo.msg.model;

public class arithmetic {
public int []answer;//答案
public int shumu;//出题数目
public String []suanshi;//算式
public void setsuanshi(String []suanshi)
{
this.suanshi=suanshi;
}

public String [] biaodashi(int n)
{
shumu=n;
answer=new int[n];
int a,b,c,d1 = 0,d,d2=0;
int []mixture=new int[2];
String []biaodashi=new String[n];

for(int i=0;i<n;i++)
{
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==5)//混合运算
{
do
{
for(int m=0;m<2;m++)
{
mixture[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(mixture[0]==0&&mixture[1]==0)
{
biaodashi[i]=a+"+"+b+"+"+d+" = ";
d1=a+b+d;
}
if(mixture[0]==1&&mixture[1]==1)
{
biaodashi[i]=a+"-"+b+"-"+d+" = ";
d2=a-b;
d1=a-b-d;
}
if(mixture[0]==0&&mixture[1]==1)
{
biaodashi[i]=a+"+"+b+"-"+d+" = ";
d1=a+b-d;
}
if(mixture[0]==1&&mixture[1]==0)
{
biaodashi[i]=a+"-"+b+"+"+d+" = ";
d2=a-b;
d1=a-b+d;
}
} while(d2<0||d1<0);
answer[i]=d1;
}
if(c==4)//单加法
{
d1=a+b;
biaodashi[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;
}
biaodashi[i]=a+"+"+b+" = ";
answer[i]=d1;
System.out.print(a+"+"+b+"= ");
}
if(c==1)//单减法
{
d1=a-b;
while(d1<0)
{
a=(int)(Math.random()*100)+1;
b=(int)(Math.random()*100)+1;
d1=a-b;
}
biaodashi[i]=a+"-"+b+" = ";
answer[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;
biaodashi[i]=a+"*"+b+" = ";
answer[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;
biaodashi[i]=a+"÷"+b+" = ";
answer[i]=d1;
System.out.print(a+"÷"+b+"= ");
}

//查重
for(int k=i-1;k>=0;k--)
{
while(biaodashi[i].equals(biaodashi[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==5)
{
do//混合运算
{
for(int m=0;m<2;m++)
{
mixture[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(mixture[0]==0&&mixture[1]==0)
{
biaodashi[i]=a+"+"+b+"+"+d+" = ";
d1=a+b+d;
}
if(mixture[0]==1&&mixture[1]==1)
{
biaodashi[i]=a+"-"+b+"-"+d+" = ";
d2=a-b;
d1=a-b-d;
}
if(mixture[0]==0&&mixture[1]==1)
{
biaodashi[i]=a+"+"+b+"-"+d+" = ";
d1=a+b-d;
}
if(mixture[0]==1&&mixture[1]==0)
{
biaodashi[i]=a+"-"+b+"+"+d+" = ";
d2=a-b;
d1=a-b+d;
}
}while(d2<0||d1<0);
answer[i]=d1;
}
if(c==4)
{
d1=a+b;
biaodashi[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;
}
biaodashi[i]=a+"+"+b+" = ";
answer[i]=d1;
System.out.print(a+"+"+b+"= ");
}
if(c==1)
{
d1=a-b;
while(d1<0)
{
a=(int)(Math.random()*100)+1;
b=(int)(Math.random()*100)+1;
d1=a-b;
}
biaodashi[i]=a+"-"+b+" = ";
answer[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;
biaodashi[i]=a+"*"+b+" = ";
answer[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;
biaodashi[i]=a+"÷"+b+" = ";
answer[i]=d1;
System.out.print(a+"÷"+b+"= ");
}
}
}
}
return biaodashi;
}

}

chutijiemian.jsp:

<%@ 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:华文新魏;font-size:5em">WELCOME</h1>
<body style="background:url(C:/Users/888888/Desktop/8.jpg)">

<form action="Chuti.jsp" method="post">
<table align="center" border="0" width="500" style="margin:00px 200px 00px 5px">
<tr>
<td style="font-family:华文新魏;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:华文新魏;font-size:2em;width:500px" align="right">设置时间: </td>
<td>
<input style="width:100px;height:30px;" type="text" name="usertime" />
</td>
</tr>

<tr><td style="width:150px;height:40px;"></td></tr> <!-- 加了一个自己设置的高度的空行 -->
<tr align="center">
<td colspan="2">
<input style="width:100px;height:30px; margin:00px 20px 00px 150px" type="submit" value="开始答题" />
</body>
</html>

chuti.jsp:

<%@page import="com.jaovo.msg.model.arithmetic"%>
<%@ 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();//onload 事件会在页面或图像加载完成后立即发生。
}

</script>
<h1 style="font-family:华文新魏;font-size:4em" >开始答题</h1>
<td style="font-family:华文新魏;font-size:1em;width:500px" align="right">倒计时:</td>
<p id = "txt"></p>
<form action="Result.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;
}//字符串类型的数字转换为整型 成为参数

arithmetic demo=new arithmetic();//定义对象
String []biaodashi1=new String[num1];
biaodashi1=demo.biaodashi(num1);//接收算式
demo.setsuanshi(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);//用于下一个界面的接收本界面的这个类的全部内容result 所以定义的对象
%>
<tr>
<button id="anniu" onclick="test()" type="submit">提交</button>

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

Result.jsp:

<%@page import="com.jaovo.msg.model.arithmetic"%>
<%@ 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:华文新魏;font-size:5em">正确答案</h1>
<%
//接收客户端传递过来的参数
arithmetic newdemo=new arithmetic();
newdemo=(arithmetic)session.getAttribute("jieshou");//用于接收CHUti界面传过来的数 (对象)
String []yoursolution=new String[newdemo.shumu];//接收传过来的文本框的答案
int sumright=0,sumerror=0,empty=0;
for(int i=0;i<newdemo.shumu;i++)
{
request.setCharacterEncoding("UTF-8");
out.print(newdemo.suanshi[i]);//正确的算式
yoursolution[i] = request.getParameter("result["+i+"]");//你的答案
out.println(yoursolution[i]);
%>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<%
out.println("正确答案是: ");
out.println(newdemo.answer[i]);//正确的答案
%>
&nbsp;&nbsp;&nbsp;&nbsp;
<%
int num1=0;
int x=1;
for(int m=0;m<yoursolution[i].length();m++)
{
num1+=(yoursolution[i].charAt(yoursolution[i].length()-m-1)-'0')*x;
x*=10;
}//字符串类型的数字转换为整型 用于和正确答案比较 因为从出题界面接受的答案是字符串类型
if(yoursolution[i].equals(""))
{
out.println("你没有回答哦!");
empty++;
}
else if(num1==newdemo.answer[i])
{
sumright++;
out.println("恭喜你!回答正确!");
}
else
{
sumerror++;
out.println("回答错误,再接再厉!");
}
out.println("<br/>");//换行
}
out.println("回答正确了"+sumright+"道题!");
out.println("<br/>");//换行
out.println("回答错误了"+sumerror+"道题!");
out.println("<br/>");//换行
out.println("没有回答"+empty+"道题!");
out.println("<br/>");//换行
%>
</tr>
<a href="chutishumu.jsp">退出</a>
</body>
</html>

运行结果:

已接触Javawe快一个月了,因为是刚刚接触这个网页吧,所以会的很少,不会的很多。对于Javaweb,我感觉是个很神奇的,参数的传递,自动调用,自动启动等等,这些都是没见过的,当然还要进一步理解!写的慢的原因,对Javaweb不是很了解,只能一步一步来

时间记录日志:

学生:马佳慧                                            日期:2017/12/5

教师:王建民                                            课程:软件工程概论

日期\时间

开始时间

结束时间

中断时间

净时间

活动

备注

12/1

9:00

11:30

10:30

120分钟

自习,练习

课间

14:00

16:30

15:30

80分钟

练习

中场休息

12/2

9:30

11:00

10:30

80分钟

听课,练习

中场休息

14:30

18:00

16:00

200分钟

上课

中场休息

12/3

8:00

11:30

10:00

150分钟

写作业,练习,提交作业

写 四则

12/4

19:00

22:00

20:30

150分钟

练习,自习

课间

12/5

8:00

16:50

8:50/9:50/12:00

180分钟

改错,补充,写总结上课

课间

四则运算————javaweb版的更多相关文章

  1. 四则运算自动出题之javaweb版

    四则运算出题机之JAVAWEB版 要求还是和之前的出题形式一样 begin.jpg <%@ page language="java" contentType="te ...

  2. 结对编程项目——四则运算vs版

    结对编程项目--四则运算vs版 1)小伙伴信息:        学号:130201238 赵莹        博客地址:点我进入 小伙伴的博客 2)实现的功能: 实现带有用户界面的四则运算:将原只能在 ...

  3. 四则运算GUI版

    小学四则运算界面版 李永豪 201421123117 郑靖涛 201421123114 coding 地址:https://git.coding.net/ras/work2.git 一.题目描述 我们 ...

  4. 四则运算APP版

    (一)四则运算APP版 这这个Demo的目的就是强化一下本周学习的Android的Jetpack里的新内容,接下来我将通过这个Demo来展示我所学到的新知识. 先列出新学到的知识:ViewModel, ...

  5. Javaweb版四则运算

    显示出题界面shu01.jsp <%@ page language="java" contentType="text/html; charset=UTF-8&quo ...

  6. 实验二 四则运算 完成版 ver.1

    package size; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JMenuBar; im ...

  7. 四则运算(Android)版

    实验题目: 将小学四则运算整合成网页版或者是Android版.实现有无余数,减法有无负数.... 设计思路: 由于学到的基础知识不足,只能设计简单的加减乘除,界面设计简单,代码量少,只是达到了入门级的 ...

  8. 四则运算web版需求规格说明书

    目录 1引言... 4 1.1  目的... 4 1.2  背景... 4 1.3  术语... 4 1.4  预期读者与阅读建议... 5 1.5  参考资料... 6 1.6  需求描述约定... ...

  9. Homework_4 四则运算 - C#版

    题目要求 :http://www.cnblogs.com/gdfhp/p/5311937.html 结对同伴: 姓名:胡仕辉   学号:130201225   博客地址:http://www.cnbl ...

随机推荐

  1. Vue 使用comouted计算属性

    computed计算属性 使用方法见代码: <!doctype html> <html lang="en"> <head> <meta c ...

  2. Manthan, Codefest 18 (rated, Div. 1 + Div. 2) E bfs + 离线处理

    https://codeforces.com/contest/1037/problem/E 题意 有n个人,m天,在第i天早上,x和y会成为朋友,每天晚上大家都要上车,假如一个人要上车那么他得有至少k ...

  3. MySQL实战45讲学习笔记:第三十五讲

    一.本节概述 在上一篇文章中,我和你介绍了 join 语句的两种算法,分别是 Index Nested-LoopJoin(NLJ) 和 Block Nested-Loop Join(BNL). 我们发 ...

  4. linux jdk1.8 32位下载永久地址,ubuntu,centos,java

    链接: https://pan.baidu.com/s/16zSC0HZGFjrTAXrW6eyHzg 提取码: cj7m 复制这段内容后打开百度网盘手机App,操作更方便哦

  5. ubuntu16.04安装QGIS工具

    指令安装安装qgis可以通过添加安装源的形式进行 sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable sudo apt-get updat ...

  6. Entity Framework Core 练习参考

    项目地址:https://gitee.com/dhclly/IceDog.EFCore 项目介绍 对 Microsoft EntityFramework Core 框架的练习测试 参考文档教程 官方文 ...

  7. 在 Javascript 中,为什么给 form 添加了 onsubmit 事件,为什么 IE7/8 还是会提交表单?

    参考地址:http://stackoverflow.com/questions/4078245/onsubmit-return-false-has-no-effect-on-internet-expl ...

  8. f(n-1) + f(n-2)的编译器处理

    https://gcc.godbolt.org   int addx(int a){ return a + 2; } int gooo(){ return addx(3) + addx(4) + ad ...

  9. android studio学习----gradle基础

    Gradle是一种依赖管理工具,基于Groovy语言,面向Java应用为主,它抛弃了基于XML的各种繁琐配置,取而代之的是一种基于Groovy的内部领域特定(DSL)语言. 安装Gradle 在And ...

  10. Java中关于数据类型的一些问题

    Java中关于数据类型的一些问题 总结一下最近笔试遇到的一些关于Java中数据类型的一些问题. 虽然比较基础,但在实际做题却很容易出错的点,而且往往这些题出错了会给面试官很不好的感觉:你的基础不好. ...