四则运算⼆(javaweb)
最近我和我的⼩伙伴yaoyali结成对⼦,共同写⽹页版的四则运算。虽然现在还没弄好,但是⽐起上次⽤纯java写的四则运算有了很⼤改进。
⼀.存放四则运算题⽬和答案的类
package com.del;
public class DoubleOperation {
private static int operationNumber;
private static double[] result;
private static String[] question;
public static String[] getQuestion() {
return question;
}
public static void setQuestion(String[] question) {
DoubleOperation.question = question;
}
public int getOperationNumber() {
return operationNumber;
}
public void setOperationNumber(int operationNumber) {
this.operationNumber = operationNumber;
}
public double[] getResult() {
return result;
}
public void setResult(double[] result) {
}
}
⼆.Welcom页⾯
@charset "UTF-8";
/****四则运算题⽬表格(<table>)****/
.box{
margin-top: 50px;
}
/
****结果输⼊框(<input>)****/
.result{
width: 60px;
padding: 5px;
border:none;
font-size:20px;
border-bottom: solid yellowgreen 5px;
text-align:center;
}
/****题⽬(<td>)****/
.expr{
font-size: x-large;
}
/****⾮分数/运算符(<div>)*****/
.nomal{
text-align:center;
float:left;
position: relative;
top: 16px;
margin-left: 3px;
margin-right: 3px;
width="20px"
}
/****分数(<div>)****/
.fraction{
text-align:center;
float: left;
margin-left:3px;
margin-right: 3px;
width="20px"
}
/****题⽬选择*****/
.option{
text-align: center;
}
/******你准备好了吗?按钮******/
.submit1{
padding-top: 10px;
padding-bottom: 10px;
padding-left: 20px;
padding-right: 20px;
background: #C90;java valueof
font-family: "微软雅⿊";
font-weight: bold;
font-size: 20px;
}
/*****提交按钮*****/
.submit{
padding-top: 10px;
padding-bottom: 10px;
padding-left: 20px;
padding-right: 20px;
border-radius: 5px;
background: cornflowerblue;
border: none;
cursor: pointer;
color:lightyellow;
font-family: "微软雅⿊";
font-weight: bold;
font-size: 20px;
}
/******计时器*******/
.timer{
position:fixed;
top: 10px;
right: 10px;
border: none;
width:50px;
text-align: right;
background: none;
}
.pause{
position:fixed;
top: 30px;
right: 10px;
}
/****题⽬选项****/
.
option{
margin-left:auto;
margin-right:auto;
width:600px;
margin-top: 130px;
border:dashed #9ACD32 2px;
padding-top: 100px;
padding-bottom: 100px;
}
/****答题按钮*****/
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "/TR/html4/loose.dtd"> <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="css/style.css"/>
<title>⼩学⽣四则运算</title>
<style type="text/css">
body
{
background-image:url(image/2.jpg);
}
#p1{text - indent:2em;text - align:center;font:italic 35px/40px 幼圆}
</style>
</head>
<body>
<p id="p1">欢迎⼩朋友来到⼩猪佩奇的数学乐园,快跟⼩猪佩奇⼀起去冒险吧!</p>
<form action="choose.jsp" class="option">
<button class="submit1" >你准备好了吗?</button>
</form>
</body>
</html>
结果截图
三.选择出题数量及题⽬种类
choose.jsp和Connect.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "/TR/html4/loose.dtd"> <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="css/style.css"/>
<title>⼩学⽣四则运算</title>
<style type="text/css">
body{
background-image:url(image/4.jpg);
}
</style>
</head>
<body>
<div >
<a href="Welcome.jsp">退出</a><br><br>
</div>
<form action="Connect.jsp" class="option">
<center><h2>题⽬定制</h2></center>
<p>选择题⽬类型:
<select name="elementNum">
<option>2</option>
<option>3</option>
</select>元运算<br /></p>
选择题⽬数量:
<input name="count" value="10" type="radio"/>10
<input name="count" value="20" type="radio"/>20
<input name="count" value="30" type="radio"/>30
<input name="count" value="40" type="radio"/>40
<input name="count" value="50" type="radio"/>50
<input name="count" value="5000" type="radio"/>5000<br/>
<input name="count" value="1000000" type="radio"/>10000000(极限测试,慎选!!)
<br /><br />
<button class="submit" >开始答题!</button>
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "/TR/html4/loose.dtd"> <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>连接</title>
</head>
<body>
<%
String Parameter("elementNum");
String Parameter("count");
if(OperationNumber==null||"".equals(OperationNumber))
{
OperationNumber="10";
}
if(type.equals("2"))
{
response.sendRedirect("DoubleOperation.jsp?OperationNumber="+OperationNumber);
}
else
{
response.sendRedirect("ThreeOperation.jsp?OperationNumber="+OperationNumber);
}
%>
</body>
</html>
四.⼆元四则运算
DoubleOperation.jsp
<%@ page import="java.util.Random" %>
<%@ page import="java.lang.Math" %>
<%@ page import="com.del.DoubleOperation" %>
<%@ page import="java.math.BigInteger" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "/TR/html4/loose.dtd"> <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>⼆元运算</title>
</head>
<body>
<form action="doDoubleOperation.jsp" method="post">
<div >
<a href="choose.jsp">题⽬定制</a>
<a href="Welcome.jsp">退出</a><br><br>
</div>
<%
int character=0;//运算符+,-,*,/
int num1=0;//运算式中第⼀个数
int num2=0;//运算式中第⼆个数
int correct=0;//计算正确的数⽬
int error=0;//计算错误的数⽬
String operat=null;//计算式
Random random = new Random();
int Endtime=1; //跳转时间
int operationNumber=Integer.Parameter("OperationNumber"));//打印题⽬的数量
String question[]=new String[operationNumber];
double result[]=new double[operationNumber];//计算式的结果
for(int i=0;i<operationNumber;i++)//初始化计算式的结果
{
result[i]=0;
question[i]=null;
}
DoubleOperation doubleoperation=new DoubleOperation();//初始化.java⽂件中存储的计算公式个数,问题,答案 doubleoperation.setOperationNumber(operationNumber);
doubleoperation.setQuestion(question);
doubleoperation.setResult(result);
for(int i=0;i<operationNumber;i++)
{
Int(4)%4+1;
if(character==1)//计算加法
{
Int(100)%100;//随机出⼀个0~100的数
Int(100)%100;
String number1=String.valueOf(num1);
String number2=String.valueOf(num2);
operat="第("+(i+1)+")题"+number1+"+"+number2+"=";
result[i]=num1+num2;
}
else if(character==2)//计算减法
{
Int(100)%100;//随机出⼀个1~100的数
if(num1==0)
num1=num1+2;//若num1=0,则加2
num2=(Int(num1)%(num1);//随机出⼀个0~num1的数
String number1=String.valueOf(num1);
String number2=String.valueOf(num2);
operat="第("+(i+1)+")题"+number1+"-"+number2+"=";
result[i]=num1-num2;
}
else if(character==3)//计算乘法
{
Int(9)%9;//随机出⼀个0~9的数
Int(9)%9;
String number1=String.valueOf(num1);
String number2=String.valueOf(num2);
operat="第("+(i+1)+")题"+number1+"*"+number2+"=";
result[i]=num1*num2;
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论