软件工程结对作业01

1.设计思想:各部分分模块进行

2.源程序:

package MyBean;

import java.util.Random;

public class JavaBean
{
public String[] outoperater=new String[100]; //存储输出的运算式
public double[] outresult=new double[100]; //存储输出的运算式的结果
public int shengchenggeshu=0; //运算式计数
public int shengchengshushu=0; //结果计数

private int properfraction; //确定是否含有真分数
private int multiplydivide; //定义是否有乘除法,0代表没有,1代表有
private int max, min; //定义四则运算中的数的取值范围
private int minus; //定义是否有负数,0代表没有,1代表有
private int remainder; //定义是否有余数,0代表没有,1代表有
private int parentheses; //定义是否有括号,0代表没有,1代表有
private int count; //定义生成几个运算式
private int yunSFLen = 0; //记录运算符长度

//构造函数
public JavaBean()
{
// TODO Auto-generated constructor stub
}

//对类的所有属性的操作函数
public void setProperFraction(int properfraction) //真分数
{
this.properfraction=properfraction;
}
public int getProperFraction()
{
return properfraction;
}

public void setMultiplyDivide(int multiplydivide)
{
this.multiplydivide=multiplydivide;
}
public int getMultiplyDivide()
{
return multiplydivide;
}

public void setRemainder(int remainder)
{
this.remainder=remainder;
}
public int getRemainder()
{
return remainder;
}

public void setMinus(int minus)
{
this.minus=minus;
}
public int getMinus()
{
return minus;
}

public void setParentheses(int parentheses)
{
this.parentheses=parentheses;
}
public int getParentheses()
{
return parentheses;
}

public void setMax(int max)
{
this.max=max;
}
public int getMax()
{
return max;
}

public void setmin(int min)
{
this.min=min;
}
public int getmin()
{
return min;
}

public void setCount(int count)
{
this.count=count;
}
public int getCount()
{
return count;
}

public String[] getoutoperater()
{
return outoperater;
}
public double[] getoutresult()
{
return outresult;
}

//运算式的生成和的计算***************************************************************


Random random=new Random();
//生成四个运算数函数,即多运算数式子中的每个操作数
public void create_Operand(int A[], int min, int max)
{
for (int i = 0; i < 4; i++)
{
A[i] = min + random.nextInt(max - min + 1);
}
}

//若用户选择不生成除法,则只生成含有加减运算的运算符,用string类型存放运算符,并将括号也存到数组中
public void create_Operator_JiaJian(String B[], int kuohao)
{
for (int i = 0; i < 5; i++)
{
B[i] = "a";
}
if (1 == kuohao)
{
String C[]=new String[3];
for (int i = 0; i < 3; i++)
{
int Judge = random.nextInt(2);
switch (Judge)
{
case 0:
C[i] = "+"; break;
case 1:
C[i] = "-"; break;
}
}
int intLeftLocation;
intLeftLocation = 1 + random.nextInt(2);
int intRightLocation;
int a = intLeftLocation + 2;
intRightLocation = a + random.nextInt(5 - a);
B[intLeftLocation] = "(";
B[intRightLocation] = ")";
int j = 0;
for (int i = 0; i < 5; i++)
{
if ((B[i] != "(") && (B[i] != ")"))
{
B[i] = C[j];
j++;
}
}
}
else
{
for (int i = 0; i < 3; i++)
{
int Judge = random.nextInt(2);
switch (Judge)
{
case 0:
B[i] = "+"; break;
case 1:
B[i] = "-"; break;
}
}
}
}

//生成加减乘除四则运算的运算符
public void create_Operator_ChengChu(String B[])
{
for (int i = 0; i < 3; i++)
{
int Judge = random.nextInt(4);
switch (Judge)
{
case 0:
B[i] = "+"; break;
case 1:
B[i] = "+"; break;
case 2:
B[i] = "-"; break;
case 3:
B[i] = "÷"; break;
}
}
}

//生成字符数组
public void MulDivShuZus(String B[])
{
for (int i = 0; i < 3; i++)
{
create_Operator_ChengChu(B);
}
if ((B[0] == "÷") && (B[1] == "÷") && (B[2] == "÷")) //规定不能有连续的3个除法
{
int intJudge = 1 + random.nextInt(2);
switch (intJudge)
{
case 1:
B[2] = "+";
break;
case 2:
B[2] = "-";
break;
}
}
}

//判断分数中的分子分母是否合法,即分子的绝对值是否小于分母
public void judge_Fraction(int fenzi[], int fenmu[], int max)
{
if ((fenzi[0]<0) && (((fenzi[0])*(-1))>max))
{
int temp = (-1)*fenzi[0];
fenzi[0] = fenmu[0];
fenmu[0] = temp*(-1);
}

//为保证分数相加相减后仍然是真分数,将分子设为小于二分之分母的整数
if (fenzi[0] <= 0)
{
if (fenzi[0]*(-1)>(max / 2))
{
fenzi[0] = fenzi[0] / 2;
}
}
if (fenzi[0]>0)
{
if (fenzi[0]>(max / 2))
{
fenzi[0] = fenzi[0] / 2;
}
}
}

//求分子和分母的最大公约数,以便将分子分母化简到最简
public int great_common_Divisor(int fenzi, int fenmu)
{
int original_fenzi = fenzi;
int original_fenmu = fenmu;
int remainder = fenzi%fenmu;
while (remainder != 0)
{
int temp = fenmu;
fenmu = fenzi%fenmu;
fenzi = temp;
remainder = fenzi%fenmu;
}
return fenmu;
}

//计算加减运算式的值,返回一个result值
public double calculate_Jiajian(int A[], String B[], int kuohao, int minus, int min, int max)
{
if (1 == minus)
{
double result = A[0];
if (1 == kuohao)
{
result = 0;
if ((B[1] == "(") && (B[3] == ")"))
{
if (B[2] == "+")
{
result = A[1] + A[2];
}
else
{
result = A[1] - A[2];
}
if (B[0] == "+")
{
result = result + A[0];
}
else
{
result = A[0] - result;
}
if (B[4] == "+")
{
result = result + A[3];
}
else
{
result = result - A[3];
}
}
if ((B[2] == "(") && (B[4] == ")"))
{
double result1 = 0;
if (B[3] == "+")
{
result = A[2] + A[3];
}
else
{
result = A[2] - A[3];
}
if (B[0] == "+")
{
result1 = A[0] + A[1];
}
else
{
result1 = A[0] - A[1];
}
if (B[1] == "+")
{
result = result + result1;
}
else
{
result = result1 - result;
}
}
if ((B[1] == "(") && (B[4] == ")"))
{
if (B[2] == "+")
{
result = A[1] + A[2];
}
else
{
result = A[1] - A[2];
}
if (B[3] == "+")
{
result = result + A[3];
}
else
{
result = result - A[3];
}
if (B[0] == "+")
{
result = result + A[0];
}
else
{
result = A[0] - result;
}
}
return result;
}
else
{
for (int i = 0; i < 3; i++)
{
if (B[i] == "+")
{
result = result + A[i + 1];
}
else
{
result = result - A[i + 1];
}
}
return result;
}
}
else
{
double result = A[0];
if (1 == kuohao)
{
double result1=0;
if ((B[1] == "(") && (B[3] == ")"))
{
if (B[2] == "+")
{
result1 = A[1] + A[2];
}
else
{
if (A[1] > A[2])
{
result1 = A[1] - A[2];
}
else
{
A[1] = max;
result1 = A[1] - A[2];
}
}
if (B[0] == "+")
{
result1 = result1 + A[0];
}
else
{
if (A[0] > result1)
{
result1 = A[0] - result1;
}
else
{
B[0] = "+";
result1 = result1 + A[0];
}
}
if (B[4] == "+")
{
result1 = result1 + A[3];
}
else
{
if (result1 > A[3])
{
result1 = result1 - A[3];
}
else
{
A[3] = (int) (result1 / 2);
result1 = result1 - A[3];
}
}
}
if ((B[2] == "(") && (B[4] == ")"))
{
double result11 = 0;
if (B[3] == "+")
{
result11 = A[2] + A[3];
}
else
{
if (A[2] > A[3])
{
result11 = A[2] - A[3];
}
else
{
A[2] = max;
result11 = A[2] - A[3];
}
}
if (B[0] == "+")
{
result11 = A[0] + A[1];
}
else
{
if (A[0] > A[1])
{
result11 = A[0] - A[1];
}
else
{
A[0] = max;
result11 = A[0] - A[1];
}
}
if (B[1] == "+")
{
result11 = result11 + result11;
}
else
{
if (result11 > result11)
{
result11 = result11 - result11;
}
else
{
B[1] = "+";
result11 = result11 + result11;
}
}
}
if ((B[1] == "(") && (B[4] == ")"))
{
if (B[2] == "+")
{
result1 = A[1] + A[2];
}
else
{
if (A[1] > A[2])
{
result1 = A[1] - A[2];
}
else
{
A[1] = max;
result1 = A[1] - A[2];
}
}
if (B[3] == "+")
{
result1 = result1 + A[3];
}
else
{
if (result1 > A[3])
{
result1 = result1 - A[3];
}
else
{
B[3] = "+";
result1 = result1 + A[3];
}
}
if (B[0] == "+")
{
result1 = result1 + A[0];
}
else
{
if (A[0] > result1)
{
result1 = A[0] - result1;
}
else
{
B[0] = "+";
result1 = result1 + A[0];
}
}
}
return result1;
}
else
{
for (int i = 0; i < 3; i++)
{
if (B[i] == "+")
{
result = result + A[i + 1];
}
else
{
if (result>A[i + 1])
{
result = result - A[i + 1];
}
else
{
B[i] = "+";
result = result + A[i + 1];
}
}
}
return result;
}
}
}

//输出分数,并计算分数的值并且判断用户的计算是否正确
public int calculate_ProperFraction(int A[], int B[], int i, int min, int max, int print)
{
int maxi[]=new int[1];
maxi[0]=max;
int mini[]=new int[1];
mini[0]=min;
int AA[]=new int[1];
AA[0]=A[i];
int BB[]=new int[1];
BB[0]=B[i];

judge_Fraction(AA, maxi, max);
judge_Fraction(BB, maxi, max);
int divisor1 = great_common_Divisor(A[i], max);
int divisor2 = great_common_Divisor(B[i], max);
int inputfenzi, inputfenmu;
int suanfu = random.nextInt(4);
switch (suanfu)
{
case 0:
{
//cout << "请计算该分数算式(结果输入格式:分子 空格 分母):";
//cout << A[i] / divisor1 << "/" << max / divisor1 << " + " << B[i] / divisor2 << "/" << max / divisor2 << " = " << endl;
double a,b,c,d;
a=A[i] / divisor1;
b=max / divisor1;
c=B[i] / divisor2;
d=max / divisor2;
outoperater[shengchenggeshu]=""+a+"/"+b+"+"+c+"/"+d+"=";
shengchenggeshu=shengchenggeshu+1;
outresult[shengchengshushu]=a/b+c/d;
shengchengshushu=shengchengshushu+1;
break;
}
case 1:
{

//cout << "请计算该分数算式(结果输入格式:分子 空格 分母):";
//cout << A[i] / divisor1 << "/" << max / divisor1 << " - " << B[i] / divisor2 << "/" << max / divisor2 << " = " << endl;
double a,b,c,d;
a=A[i] / divisor1;
b=max / divisor1;
c=B[i] / divisor2;
d=max / divisor2;
outoperater[shengchenggeshu]=""+a+"/"+b+"-"+c+"/"+d+"=";
shengchenggeshu=shengchenggeshu+1;
outresult[shengchengshushu]=a/b-c/d;
shengchengshushu=shengchengshushu+1;
break;
}
case 2:
{
//cout << "请计算该分数算式(结果输入格式:分子 空格 分母):";
// cout << A[i] / divisor1 << "/" << max / divisor1 << " x " << B[i] / divisor2 << "/" << max / divisor2 << " = " << endl;
double a,b,c,d;
a=A[i] / divisor1;
b=max / divisor1;
c=B[i] / divisor2;
d=max / divisor2;
outoperater[shengchenggeshu]=""+a+"/"+b+"×"+c+"/"+d+"=";
shengchenggeshu=shengchenggeshu+1;
outresult[shengchengshushu]=(a/b)*(c/d);
shengchengshushu=shengchengshushu+1;
break;
}
case 3:
{
//cout << "请计算该分数算式(结果输入格式:分子 空格 分母):";
//cout << B[i] / divisor2 << "/" << max / divisor2 << " ÷ " << A[i] / divisor1 << "/" << max / divisor1 << " = " << endl;
double a,b,c,d;
a=A[i] / divisor1;
b=max / divisor1;
c=B[i] / divisor2;
d=max / divisor2;
if((c/d)==0)
{
c=c+1;
}
outoperater[shengchenggeshu]=""+a+"/"+b+"÷"+c+"/"+d+"=";
shengchenggeshu=shengchenggeshu+1;
outresult[shengchengshushu]=(a/b)/(c/d);
shengchengshushu=shengchengshushu+1;
break;
}
}
return 0;
}

//输出加减四则运算式,一种方式为输出到屏幕,另一种方式为输出到文件
public void output_JiaJian(int A[], String B[], int kuohao, int print)
{

if (1 == kuohao)
{
if ((B[1] == "(") && (B[3] == ")"))
{
//cout << A[0] << " " << B[0] << " " << B[1] << " " << A[1] << " " << B[2] << " " << A[2] << " " << B[3] << " " << B[4] << " " << A[3] << " = " << endl;
outoperater[shengchenggeshu]=""+A[0]+B[0]+B[1]+A[1]+B[2]+A[2]+B[3]+B[4]+A[3]+"=";
shengchenggeshu=shengchenggeshu+1;
}
if ((B[2] == "(") && (B[4] == ")"))
{
//cout << A[0] << " " << B[0] << " " << A[1] << " " << B[1] << " " << B[2] << " " << A[2] << " " << B[3] << " " << A[3] << " " << B[4] << " " << " = " << endl;
outoperater[shengchenggeshu]=""+A[0]+B[0]+A[1]+B[1]+B[2]+A[2]+B[3]+A[3]+B[4]+"=";
shengchenggeshu=shengchenggeshu+1;
}
if ((B[1] == "(") && (B[4] == ")"))
{
//cout << A[0] << " " << B[0] << " " << B[1] << " " << A[1] << " " << B[2] << " " << A[2] << " " << B[3] << " " << A[3] << " " << B[4] << " " << " = " << endl;
outoperater[shengchenggeshu]=""+A[0]+B[0]+B[1]+A[1]+B[2]+A[2]+B[3]+A[3]+B[4]+"=";
shengchenggeshu=shengchenggeshu+1;
}
}
else
{
for (int i = 0; i < 3; i++)
{
//cout << A[i] << " " << B[i] << " ";
outoperater[shengchenggeshu]=""+A[i]+B[i];

}
//cout << A[3] << " = " << endl;
outoperater[shengchenggeshu]=""+A[3]+"=";
shengchenggeshu=shengchenggeshu+1;
}

}

//判断用户输入的结果是否正确,给出相应的提示
public void minus_JiaJian(int A[], String B[], int min, int max, int minus, int kuohao, int print)
{
create_Operand(A, min, max);
create_Operator_JiaJian(B, kuohao);
double calculateResult = calculate_Jiajian(A, B, kuohao, minus, min, max);
outresult[shengchengshushu]=calculateResult;
shengchengshushu=shengchengshushu+1;
output_JiaJian(A, B, kuohao, print);
}

//生成运算符数组
public int YSShuZus(String B[], int kuohao)
{
int intYunSFNum;
if (0 == kuohao) //如果没有括号
{
MulDivShuZus(B);
intYunSFNum = 3;
}
else //如果有括号
{
MulDivShuZus(B); //获得没有括号的运算符数组
String chLinShi[]=new String[3]; //临时数组
for (int i = 0; i < 3; i++)
{
chLinShi[i] = B[i];
}
intYunSFNum = 3;
int intRealstring[]=new int[3];
for (int i = 0; i < 3; i++) //将运算符按优先级存储起来
{
if (B[i] == "+" || B[i] == "-")
{
intRealstring[i] = 1;
}
else
{
intRealstring[i] = 2;
}
}

for (int i = 0; i < 2; i++)
{
if (chLinShi[0] == "÷")
{
if (chLinShi[1] == "÷")
{
intYunSFNum = 5;
B[0] = "(";
B[1] = chLinShi[0];
B[2] = ")";
B[3] = chLinShi[1];
B[4] = chLinShi[2];
break;
}

}
if (intRealstring[i]<intRealstring[i + 1])
{
if (i == 0)
{
if (chLinShi[i + 1] == "÷")
{
if (chLinShi[i + 2] == "÷")
{
intYunSFNum = 7;
B[0] = "(";
B[1] = "(";
B[2] = chLinShi[0];
B[3] = ")";
B[4] = chLinShi[1];
B[5] = ")";
B[6] = chLinShi[2];
}
else
{
intYunSFNum = 5;
B[0] = "(";
B[1] = chLinShi[0];
B[2] = ")";
B[3] = chLinShi[1];
B[4] = chLinShi[2];
}
}
else
{
intYunSFNum = 5;
B[0] = "(";
B[1] = chLinShi[0];
B[2] = ")";
B[3] = chLinShi[1];
B[4] = chLinShi[2];
}
}
else
{
intYunSFNum = 5;
B[0] = chLinShi[0];
B[1] = "(";
B[2] = chLinShi[1];
B[3] = ")";
B[4] = chLinShi[2];
}
}
}
}
return intYunSFNum;
}

//

//生成两个存储数据的数组,主函数中的作用是用来进行判断是进行两位真分数的判断还是多位整数的四则运算
public void createArray(int A[], int B[], int count, int min, int max)
{
for (int i = 0; i < count; i++)
{

A[i] = min + random.nextInt(max - min + 1);
B[i] = min + random.nextInt(max - min + 1);

for (int j = 0; j < i; j++)
{
if (A[i] == A[j])
{
A[i] = min + random.nextInt(max - min + 1);
j = -1; //通过设置j,对新生成的数A[i],使其和前面的所有数进行比较,此循环重复
}
}
for (int j = 0; j < i; j++)
{
if (B[i] == B[j])
{
B[i] = min + random.nextInt(max - min + 1);
j = -1;
}
}
}
}

//生成加减运算符
public void AddRedu(String stringArry[])
{
int intJudge; //此变量分别以1,2,3,4代表+、-、×、÷

intJudge = 1 + random.nextInt(2);
switch (intJudge)
{
case 1:
{
stringArry[0] = "+";
break;
}
case 2:
{
stringArry[0] = "-";
break;
}
}
}

//生成乘除运算符
public void MulDiv(String stringArry[])
{
int intJudge; //此变量分别以1,2,3,4代表+、-、×、÷

intJudge = 1 + random.nextInt(4);
switch (intJudge)
{
case 1:
{
stringArry[0] = "+";
break;
}
case 2:
{
stringArry[0] = "-";
break;
}
case 3:
{
stringArry[0] = "×";
break;
}
case 4:
{
stringArry[0] = "÷";
break;
}
}
}

//判断乘除号,生成字符数组
public void MulDivShuZu(String stringMDYSF[], int intMulDiv)
{
if (intMulDiv == 0) //如果没有乘除法
{
int intJudge; //此变量分别以1,2,3,4代表+、-、×、÷
for (int i = 0; i < 3; i++)
{
intJudge = 1 + random.nextInt(2);
switch (intJudge)
{
case 1:
{
stringMDYSF[i] = "+";
break;
}
case 2:
{
stringMDYSF[i] = "-";
break;
}
}
}
}
else //如果有乘除法
{
int intJudge; //此变量分别以1,2,3,4代表+、-、×、÷
for (int i = 0; i < 3; i++)
{
intJudge = 1 + random.nextInt(4);
switch (intJudge)
{
case 1:
{
stringMDYSF[i] = "+";
break;
}
case 2:
{
stringMDYSF[i] = "-";
break;
}
case 3:
{
stringMDYSF[i] = "×";
break;
}
case 4:
{
stringMDYSF[i] = "÷";
break;
}
}
}

for (int i = 0; i < 3; i++) //不能有连续的3个除法
{
if (stringMDYSF[i] == "÷")
{
if (stringMDYSF[i + 1] == "÷" && stringMDYSF[i + 2] == "÷")
{
intJudge = 1 + random.nextInt(2);
switch (intJudge)
{
case 1:
{
stringMDYSF[i] = "+";
break;
}
case 2:
{
stringMDYSF[i] = "-";
break;
}
}
}
}
}

}
}

//生成运算符数组
public void YSShuZu(String stringYunSF[], int intMulDiv, int intKuoHao, int intYunSFNum[])
{
if (0 == intKuoHao) //如果没有括号
{
MulDivShuZu(stringYunSF, intMulDiv);
intYunSFNum[0] = 3;
}
else //如果有括号
{
MulDivShuZu(stringYunSF, intMulDiv); //获得没有括号的运算符数组

String chLinShi[]=new String[3]; //临时数组
for (int i = 0; i < 3; i++)
{
chLinShi[i] = stringYunSF[i];
}

if (0 == intMulDiv) //如果没有乘除,只有加减,加上括号
{
int intKHaoNum;
intKHaoNum = 1;

if (1 == intKHaoNum) //加一个括号
{
intYunSFNum[0] = 5; //运算符的个数为5个
int intLeftLocation;
intLeftLocation = 1 + random.nextInt(2);
int intRightLocation;
int a = intLeftLocation + 2;
intRightLocation = a + random.nextInt(5 - a);

stringYunSF[intLeftLocation] = "(";
stringYunSF[intRightLocation] = ")";

int j = 0;
for (int i = 0; i < 5; i++)
{
if ((stringYunSF[i] != "(") && (stringYunSF[i] != ")"))
{
stringYunSF[i] = chLinShi[j];
j++;
}
}


}
/* 用于判断生成几个括号时使用此功能
else //加两个括号
{
intYunSFNum = 7; //运算符个数为7个
stringYunSF[0] = "(";
stringYunSF[1] = chLinShi[0];
stringYunSF[2] = ")";
stringYunSF[3] = chLinShi[1];
stringYunSF[4] = "(";
stringYunSF[5] = chLinShi[2];
stringYunSF[6] = ")";
}*/
}
else //如果有乘除,加上括号
{
intYunSFNum[0] = 3;

int intRealstring[]=new int[3];
for (int i = 0; i < 3; i++) //将运算符按优先级存储起来
{
if (stringYunSF[i] == "+" || stringYunSF[i] == "-")
{
intRealstring[i] = 1;
}
else
{
intRealstring[i] = 2;
}
}

for (int i = 0; i < 2; i++)
{
if (chLinShi[0] == "÷")
{
if (chLinShi[1] == "÷")
{
intYunSFNum[0] = 5;
stringYunSF[0] = "(";
stringYunSF[1] = chLinShi[0];
stringYunSF[2] = ")";
stringYunSF[3] = chLinShi[1];
stringYunSF[4] = chLinShi[2];
break;
}

}
if (intRealstring[i]<intRealstring[i + 1])
{
if (i == 0)
{
if (chLinShi[i + 1] == "÷")
{
if (chLinShi[i + 2] == "÷")
{
intYunSFNum[0] = 7;
stringYunSF[0] = "(";
stringYunSF[1] = "(";
stringYunSF[2] = chLinShi[0];
stringYunSF[3] = ")";
stringYunSF[4] = chLinShi[1];
stringYunSF[5] = ")";
stringYunSF[6] = chLinShi[2];
}
else
{
intYunSFNum[0] = 5;
stringYunSF[0] = "(";
stringYunSF[1] = chLinShi[0];
stringYunSF[2] = ")";
stringYunSF[3] = chLinShi[1];
stringYunSF[4] = chLinShi[2];
}
}
else
{
intYunSFNum[0] = 5;
stringYunSF[0] = "(";
stringYunSF[1] = chLinShi[0];
stringYunSF[2] = ")";
stringYunSF[3] = chLinShi[1];
stringYunSF[4] = chLinShi[2];
}
}
else
{
intYunSFNum[0] = 5;
stringYunSF[0] = chLinShi[0];
stringYunSF[1] = "(";
stringYunSF[2] = chLinShi[1];
stringYunSF[3] = ")";
stringYunSF[4] = chLinShi[2];
}
}
}

}
}


}

//函数实现有无余数
public void RemainderFouction(int intNum[], String stringYunSuanFu[], int intYunSuanFNu[])
{

//包括括号和乘除法的区分
//首先实现对乘除法有无余数的判断
//其次加入括号,判断括号内的乘除法有无余数的实现

//对运算符数组循环寻找括号和乘除号
int intCycleNum = 0;
int intParentNum = 0;
for (intCycleNum = 0; intCycleNum < intYunSuanFNu[0]; intCycleNum++)
{
if ((stringYunSuanFu[intCycleNum] == "(") || (stringYunSuanFu[intCycleNum] == ")"))
{
intParentNum += 1;
}

if (stringYunSuanFu[intCycleNum] == "÷")
{
if (intNum[intCycleNum + 1 - intParentNum] == 0)
{
intNum[intCycleNum + 1 - intParentNum] = 1 + random.nextInt(10);
}

if (intCycleNum != 0 && stringYunSuanFu[intCycleNum - 1] == ")") //此IF语句是测试(a+b)÷c的情况
{
int num;
num = intCycleNum - intParentNum; //标识没有括号的字符数组中除号的位置

int intSum; //括号内的数的运算结果
int intLeft; //括号内参与运算的左边的数
int intRight; //括号内参与运算的右边的数
String strYunSF;
intLeft = intNum[num - 1];
intRight = intNum[num];
strYunSF = stringYunSuanFu[intCycleNum - 2];
if (strYunSF == "+")
{
intSum = intLeft + intRight;
}
else if (strYunSF == "-")
{
intSum = intLeft - intRight;
if (intSum < 0)
{
intNum[num - 1] = intRight;
intNum[num] = intLeft;
intSum = intRight - intLeft;
}

}
else if (strYunSF == "×")
{
intSum = intLeft * intRight;
}
else
{
intSum = intLeft / intRight;
}

if (intSum < 0)
{
int a;
a = intNum[num];
intNum[num] = intNum[num + 1];
intNum[num + 1] = intNum[num];
intSum = intNum[num] - intNum[num + 1];
}

int intYushu; //余数
intYushu = intSum % (intNum[num + 1]); //除号两边的数求商
if (intYushu != 0)
{
if (intSum == 1)
{
intNum[num + 1] = 1;
}
else
{
int j = intSum - 1;
for (int i = 0; i < intSum; i++)
{
intYushu = intSum%j;
if (intYushu == 0)
{
intNum[num + 1] = j;
break;
}
j--;
}
}

}

//下面是(a+b)÷c÷d的情况
if (stringYunSuanFu[intCycleNum + 1] == "÷")
{
int intOneResult; //intOneReslut=(a+b)÷c
intOneResult = intSum / intNum[num + 1];
int intSecResult; //intSecResult=(a+b)÷c÷d
if (intNum[num + 2] == 0)
{
intNum[num + 2] = 1 + random.nextInt(10);
}
intSecResult = intOneResult % (intNum[num + 2]);

if (intSecResult != 0)
{
if (intOneResult == 1)
{
intNum[num + 2] = 1;
}
else
{
int intSecYue;
intSecYue = intOneResult - 1;

for (int i = 0; i < intOneResult; i++)
{
intSecResult = intOneResult%intSecYue;
if (intSecResult == 0)
{
intNum[num + 2] = intSecYue;
break;
}
intSecYue--;
}
}

}

}

}
else //a÷b的情况
{
int num;
num = intCycleNum - intParentNum;

int YuShu;
if (intNum[num + 1] == 0)
{
intNum[num + 1] = 1 + random.nextInt(10);
}
YuShu = (intNum[num]) % (intNum[num + 1]);
if (YuShu != 0)
{
if (intNum[num] == 1)
{
intNum[num + 1] = 1;
}
else
{
int j = intNum[num] - 1;
for (int i = 0; i < intNum[num]; i++)
{
YuShu = intNum[num] % j;
if (YuShu == 0)
{
intNum[num + 1] = j;
break;
}
j--;
}
}

}

//下面是a÷b÷c的情况
if (stringYunSuanFu[intCycleNum + 1] == "÷")
{
int OneRes;
OneRes = intNum[num] % intNum[num + 1];
if (OneRes != 0)
{
int j;
j = intNum[num] - 1;
for (int i = 0; i < intNum[num]; i++)
{
OneRes = intNum[num] % j;
if (OneRes == 0)
{
intNum[num + 1] = j;
break;
}
j--;
}
}
OneRes = intNum[num] / intNum[num + 1];
int yushus;
if (intNum[num + 2] == 0)
{
intNum[num + 2] = 1 + random.nextInt(10);
}
yushus = OneRes % (intNum[num + 2]);
if (yushus != 0)
{
if (OneRes == 1)
{
intNum[num + 2] = 1;
}
else
{
int yueshu;
yueshu = OneRes - 1;
for (int i = 0; i < OneRes; i++)
{
yushus = OneRes%yueshu;
if (yushus == 0)
{
intNum[num + 2] = yueshu;
break;
}
yueshu--;
}
}

}
}
}
}

}

//
if (stringYunSuanFu[0] == "÷" && stringYunSuanFu[1] == "(" && stringYunSuanFu[3] == ")") //a÷(b+c)
{
int intTemps;
if (stringYunSuanFu[2] == "+")
{
intTemps = intNum[1] + intNum[2];
int yushuab;
yushuab = intNum[0] % intTemps;
if (yushuab != 0)
{
intNum[0] = 2 * intTemps;
}
//cout << "yueshu=" << yushuab << " ";
//cout << "第一种情况:" << "intTemps=" << intTemps << " " << "intNum[0]=" << intNum[0] << endl;
}
if (stringYunSuanFu[2] == "-")
{
intTemps = intNum[1] - intNum[2];
if (intTemps < 0)
{
int aaa;
aaa = intNum[1];
intNum[1] = intNum[2];
intNum[2] = aaa;

intTemps = intNum[1] - intNum[2];
}
if (intTemps == 0)
{
intNum[2] = 1 + random.nextInt(10);
intNum[1] = intNum[2] + random.nextInt(3);
intTemps = intNum[1] - intNum[2];
}
int yushua;
yushua = intNum[0] % intTemps;
if (yushua != 0)
{
intNum[0] = 2 * intTemps;
}

//cout << "yueshu=" << yushua << " ";
//cout << "第二种情况:" << "intTemps=" << intTemps << " " << "intNum[0]=" << intNum[0] << endl;
}

}
}

//含有乘除法的计算
public double OperatorMD(int intYunSuanShu[], String strYunSuanFu[], int YunSuanfuN[])
{
double jieguo = 0;

if ((strYunSuanFu[0] == "(") && (strYunSuanFu[1] == "("))
{
double jieguo1;
if (strYunSuanFu[2] == "+")
{
jieguo = (intYunSuanShu[0] + intYunSuanShu[1]) / intYunSuanShu[2] / intYunSuanShu[3];
}
else
{
jieguo = (intYunSuanShu[0] - intYunSuanShu[1]) / intYunSuanShu[2] / intYunSuanShu[3];
}
}
if (strYunSuanFu[0] == "(")
{
double jieguo1;
if (strYunSuanFu[1] == "+")
{
jieguo1 = intYunSuanShu[0] + intYunSuanShu[1];
}
else if (strYunSuanFu[1] == "-")
{
jieguo1 = intYunSuanShu[0] - intYunSuanShu[1];
}
else
{
jieguo1 = intYunSuanShu[0] / intYunSuanShu[1];
}

if (strYunSuanFu[3] == "×")
{
jieguo1 = jieguo1*intYunSuanShu[2];
}
else
{
jieguo1 = jieguo1 / intYunSuanShu[2];
}

if (strYunSuanFu[4] == "+")
{
jieguo = jieguo1 + intYunSuanShu[3];
}
else if (strYunSuanFu[4] == "-")
{
jieguo = jieguo1 - intYunSuanShu[3];
}
else if (strYunSuanFu[4] == "×")
{
jieguo = jieguo1 * intYunSuanShu[3];
}
else
{
jieguo = jieguo1 / intYunSuanShu[3];
}
}

if (strYunSuanFu[1] == "(" && strYunSuanFu[0] != "(")
{
int jieguo1;
if (strYunSuanFu[2] == "+")
{
if (strYunSuanFu[0] == "+")
{
if (strYunSuanFu[4] == "×")
{
jieguo = intYunSuanShu[0] + (intYunSuanShu[1] + intYunSuanShu[2])*intYunSuanShu[3];
//cout << "+(+)*" << endl;
}
else
{
jieguo = intYunSuanShu[0] + (intYunSuanShu[1] + intYunSuanShu[2]) / intYunSuanShu[3];
//cout << "+(+)/" << endl;
}
}
if (strYunSuanFu[0] == "-")
{
if (strYunSuanFu[4] == "×")
{
jieguo = intYunSuanShu[0] - (intYunSuanShu[1] + intYunSuanShu[2])*intYunSuanShu[3];
//cout << "-(+)*" << endl;
}
else
{
jieguo = intYunSuanShu[0] - (intYunSuanShu[1] + intYunSuanShu[2]) / intYunSuanShu[3];
//cout << "-(+)/" << endl;
}
}
if (strYunSuanFu[0] == "×")
{
if (strYunSuanFu[4] == "×")
{
jieguo = intYunSuanShu[0] * (intYunSuanShu[1] + intYunSuanShu[2])*intYunSuanShu[3];
//cout << "*(+)*" << endl;
}
else
{
jieguo = intYunSuanShu[0] * (intYunSuanShu[1] + intYunSuanShu[2]) / intYunSuanShu[3];
//cout << "*(+)/" << endl;
}
}
if (strYunSuanFu[0] == "÷")
{
if (strYunSuanFu[4] == "×")
{
jieguo = intYunSuanShu[0] / (intYunSuanShu[1] + intYunSuanShu[2])*intYunSuanShu[3];
//cout << "/(+)*" << endl;
}
else
{
jieguo = intYunSuanShu[0] / (intYunSuanShu[1] + intYunSuanShu[2]) / intYunSuanShu[3];
//cout << "/(+)/" << endl;
}
}
}
else
{
if (strYunSuanFu[0] == "+")
{
if (strYunSuanFu[4] == "×")
{
jieguo = intYunSuanShu[0] + (intYunSuanShu[1] - intYunSuanShu[2])*intYunSuanShu[3];
//cout << "+(-)*" << endl;
}
else
{
jieguo = intYunSuanShu[0] + (intYunSuanShu[1] - intYunSuanShu[2]) / intYunSuanShu[3];
//cout << "+(-)/" << endl;
}
}
if (strYunSuanFu[0] == "-")
{
if (strYunSuanFu[4] == "×")
{
jieguo = intYunSuanShu[0] - (intYunSuanShu[1] - intYunSuanShu[2])*intYunSuanShu[3];
//cout << "-(-)*" << endl;
}
else
{
jieguo = intYunSuanShu[0] - (intYunSuanShu[1] - intYunSuanShu[2]) / intYunSuanShu[3];
//cout << "-(-)*" << endl;
}
}
if (strYunSuanFu[0] == "×")
{
if (strYunSuanFu[4] == "×")
{
jieguo = intYunSuanShu[0] * (intYunSuanShu[1] - intYunSuanShu[2])*intYunSuanShu[3];
//cout << "*(-)*" << endl;
}
else
{
jieguo = intYunSuanShu[0] * (intYunSuanShu[1] - intYunSuanShu[2]) / intYunSuanShu[3];
//cout << "*(-)/" << endl;
}
}
if (strYunSuanFu[0] == "÷")
{
if (strYunSuanFu[4] == "×")
{
int ab = intYunSuanShu[1] - intYunSuanShu[2];
if (ab == 0)
{
intYunSuanShu[1] = 8;
intYunSuanShu[2] = 7 - random.nextInt(4);
}
jieguo = intYunSuanShu[0] / (intYunSuanShu[1] - intYunSuanShu[2])*intYunSuanShu[3];
//cout << "/(-)*" << endl;
}
else
{
int ab = intYunSuanShu[1] - intYunSuanShu[2];
if (ab == 0)
{
intYunSuanShu[1] = 8;
intYunSuanShu[2] = 7 - random.nextInt(4);
}
jieguo = intYunSuanShu[0] / (intYunSuanShu[1] - intYunSuanShu[2]) / intYunSuanShu[3];
//cout << "/(-)/" << endl;
}
}
}

}
if ((strYunSuanFu[0] != "(") && (strYunSuanFu[1] != "("))
{
int jieguo1;
if (strYunSuanFu[0] == "+")
{
if (strYunSuanFu[1] == "+")
{
if (strYunSuanFu[2] == "+")
{
jieguo = intYunSuanShu[0] + intYunSuanShu[1] + intYunSuanShu[2] + intYunSuanShu[3];
}
else
{
jieguo = intYunSuanShu[0] + intYunSuanShu[1] + intYunSuanShu[2] - intYunSuanShu[3];
}
}
else
{
if (strYunSuanFu[2] == "+")
{
jieguo = intYunSuanShu[0] + intYunSuanShu[1] - intYunSuanShu[2] + intYunSuanShu[3];
}
else
{
jieguo = intYunSuanShu[0] + intYunSuanShu[1] - intYunSuanShu[2] - intYunSuanShu[3];
}
}
}
if (strYunSuanFu[0] == "-")
{
if (strYunSuanFu[1] == "+")
{
if (strYunSuanFu[2] == "+")
{
jieguo = intYunSuanShu[0] - intYunSuanShu[1] + intYunSuanShu[2] + intYunSuanShu[3];
}
else
{
jieguo = intYunSuanShu[0] - intYunSuanShu[1] + intYunSuanShu[2] - intYunSuanShu[3];
}
}
if (strYunSuanFu[1] == "-")
{
if (strYunSuanFu[2] == "+")
{
jieguo = intYunSuanShu[0] - intYunSuanShu[1] - intYunSuanShu[2] + intYunSuanShu[3];
}
else
{
jieguo = intYunSuanShu[0] - intYunSuanShu[1] - intYunSuanShu[2] - intYunSuanShu[3];
}
}
if (strYunSuanFu[1] == "×")
{
if (strYunSuanFu[2] == "+")
{
jieguo = intYunSuanShu[0] - intYunSuanShu[1] * intYunSuanShu[2] + intYunSuanShu[3];
}
else
{
jieguo = intYunSuanShu[0] - intYunSuanShu[1] * intYunSuanShu[2] - intYunSuanShu[3];
}
}

if (strYunSuanFu[1] == "÷")
{
if (strYunSuanFu[2] == "+")
{
jieguo = intYunSuanShu[0] - intYunSuanShu[1] / intYunSuanShu[2] + intYunSuanShu[3];
}
else
{
jieguo = intYunSuanShu[0] - intYunSuanShu[1] / intYunSuanShu[2] - intYunSuanShu[3];
}
}
}

if (strYunSuanFu[0] == "×")
{
if (strYunSuanFu[1] == "+")
{
if (strYunSuanFu[2] == "+")
{
jieguo = intYunSuanShu[0] * intYunSuanShu[1] + intYunSuanShu[2] + intYunSuanShu[3];
}
else
{
jieguo = intYunSuanShu[0] * intYunSuanShu[1] + intYunSuanShu[2] - intYunSuanShu[3];
}
}
if (strYunSuanFu[1] == "-")
{
if (strYunSuanFu[2] == "+")
{
jieguo = intYunSuanShu[0] * intYunSuanShu[1] - intYunSuanShu[2] + intYunSuanShu[3];
}
else
{
jieguo = intYunSuanShu[0] * intYunSuanShu[1] - intYunSuanShu[2] - intYunSuanShu[3];
}
}
if (strYunSuanFu[1] == "×")
{
if (strYunSuanFu[2] == "+")
{
jieguo = intYunSuanShu[0] * intYunSuanShu[1] * intYunSuanShu[2] + intYunSuanShu[3];
}
if (strYunSuanFu[2] == "-")
{
jieguo = intYunSuanShu[0] * intYunSuanShu[1] * intYunSuanShu[2] - intYunSuanShu[3];
}
if (strYunSuanFu[2] == "×")
{
jieguo = intYunSuanShu[0] * intYunSuanShu[1] * intYunSuanShu[2] * intYunSuanShu[3];
}
if (strYunSuanFu[2] == "÷")
{
jieguo = intYunSuanShu[0] * intYunSuanShu[1] * intYunSuanShu[2] / intYunSuanShu[3];
}
}
if (strYunSuanFu[1] == "÷") //strYunSuanFu[1]=="÷"
{
if (strYunSuanFu[2] == "+")
{
jieguo = intYunSuanShu[0] * intYunSuanShu[1] / intYunSuanShu[2] + intYunSuanShu[3];
}
if (strYunSuanFu[2] == "-")
{
jieguo = intYunSuanShu[0] * intYunSuanShu[1] / intYunSuanShu[2] - intYunSuanShu[3];
}
if (strYunSuanFu[2] == "×")
{
jieguo = intYunSuanShu[0] * intYunSuanShu[1] / intYunSuanShu[2] * intYunSuanShu[3];
}
if (strYunSuanFu[2] == "÷")
{
jieguo = intYunSuanShu[0] * intYunSuanShu[1] / intYunSuanShu[2] / intYunSuanShu[3];
}
}
}
if (strYunSuanFu[0] == "÷")
{
if (strYunSuanFu[1] == "+")
{
if (strYunSuanFu[2] == "+")
{
jieguo = intYunSuanShu[0] / intYunSuanShu[1] + intYunSuanShu[2] + intYunSuanShu[3];
}
else
{
jieguo = intYunSuanShu[0] / intYunSuanShu[1] + intYunSuanShu[2] - intYunSuanShu[3];
}
}
if (strYunSuanFu[1] == "-")
{
if (strYunSuanFu[2] == "+")
{
jieguo = intYunSuanShu[0] / intYunSuanShu[1] - intYunSuanShu[2] + intYunSuanShu[3];
}
else
{
jieguo = intYunSuanShu[0] / intYunSuanShu[1] - intYunSuanShu[2] - intYunSuanShu[3];
}
}
if (strYunSuanFu[1] == "×")
{
if (strYunSuanFu[2] == "+")
{
jieguo = intYunSuanShu[0] / intYunSuanShu[1] * intYunSuanShu[2] + intYunSuanShu[3];
}
if (strYunSuanFu[2] == "-")
{
jieguo = intYunSuanShu[0] / intYunSuanShu[1] * intYunSuanShu[2] - intYunSuanShu[3];
}
if (strYunSuanFu[2] == "×")
{
jieguo = intYunSuanShu[0] / intYunSuanShu[1] * intYunSuanShu[2] * intYunSuanShu[3];
}
if (strYunSuanFu[2] == "÷")
{
jieguo = intYunSuanShu[0] / intYunSuanShu[1] * intYunSuanShu[2] / intYunSuanShu[3];
}
}

}
}


return jieguo;
}

//乘除运算的输出
public void MDOutput(int intNumC[], String stringOperator[], int intYunSFLen[],int intPrintS)
{
//对运算式进行输出
int fuhaojishus0 = 0;
for (int shuchushuzi = 0; shuchushuzi < 4; shuchushuzi++)
{
if (shuchushuzi == 0)
{
if (stringOperator[0] == "(")
{
//cout << stringOperator[0];原始的
outoperater[shengchenggeshu]=""+stringOperator[0];
fuhaojishus0 = 1;

if (stringOperator[1] == "(")
{
//cout << stringOperator[0];原始的
outoperater[shengchenggeshu]=""+stringOperator[0];
fuhaojishus0 = 2;
}
}

}

//cout << intNumC[shuchushuzi];原始的
outoperater[shengchenggeshu]=""+intNumC[shuchushuzi];

for (; fuhaojishus0 < intYunSFLen[0];)
{
while (stringOperator[fuhaojishus0] == ")")
{
//cout << ")";
outoperater[shengchenggeshu]=""+")";
fuhaojishus0 += 1;
}
if (fuhaojishus0 < intYunSFLen[0])
{
//cout << stringOperator[fuhaojishus0]; //输出右括号紧邻的运算符或者是输出第一个符号
outoperater[shengchenggeshu]=""+stringOperator[fuhaojishus0];
}

fuhaojishus0 += 1;
while (stringOperator[fuhaojishus0] == "(")
{
//cout << "(";
outoperater[shengchenggeshu]=""+"(";
fuhaojishus0 += 1;
}
break;
}
}

shengchenggeshu=shengchenggeshu+1;
}

//

public void output_ChengChu(int A[], String B[], int min, int max, int kuohao, int print)
{
int kuohaoNum = 0;

create_Operand(A, min, max);
MulDivShuZus(B);
int[] suanfuNum=new int[1];
suanfuNum[0] = YSShuZus(B, kuohao);
RemainderFouction(A, B, suanfuNum);
if (3 == suanfuNum[0])
{
//cout << A[0] << " " << B[0] << " " << A[1] << " " << B[1] << " " << A[2] << " " << B[2] << " " << A[3] << " = " << endl;
outoperater[shengchenggeshu]=""+A[0]+B[0]+A[1]+B[1]+A[2]+B[2]+A[3]+"=";
shengchenggeshu=shengchenggeshu+1;
}
else
{
for (int i = 0; i < suanfuNum[0]; i++)
{
if ((B[i] == "(") || (B[i] == ")"))
{
if (i == 0 || ((i != 0) && B[i] == "("))
{
kuohaoNum++;
//cout << B[i];
outoperater[shengchenggeshu]=""+B[i];
continue;
}
else
{
//cout << A[i - kuohaoNum];
outoperater[shengchenggeshu]=""+A[i - kuohaoNum];
kuohaoNum++;
//cout << B[i];
outoperater[shengchenggeshu]=""+B[i];
continue;
}
}
else
{
if (B[i - 1] == "(")
{
//cout << A[i - kuohaoNum] << B[i];
outoperater[shengchenggeshu]=""+A[i - kuohaoNum] + B[i];
}
else
{
//cout << B[i] << A[i - kuohaoNum + 1];
outoperater[shengchenggeshu]=""+B[i] + A[i - kuohaoNum + 1];
}
}
}
//cout << " = " << endl;
outoperater[shengchenggeshu]=""+"=";
shengchenggeshu=shengchenggeshu+1;
}
}

//主函数
public int Operater()
{
int intPrintStyle=0;
int intYunSFLen[] = new int[1]; //记录运算符长度
intYunSFLen[0]=0;

double dobResult; //记录结果值
int intNumA[]=new int[100];
int intNumB[]=new int[100]; //两个数组,存储运算数
createArray(intNumA, intNumB, count, min, max); //生成两个数组

String stringOperator[]=new String[10];
for (int i = 0; i < 10; i++)
{
stringOperator[i] = "a";
}
int intNumC[]=new int[4]; //运算数的数组,存储4个数

for (int outI = 0; outI < count; outI++)
{
if (intNumA[outI] < intNumB[outI]) //生成多位整数进行运算
{
for (int i = 0; i < 4; i++) //生成数组,存储4个整数
{
intNumC[i] = min + random.nextInt(max - min + 1);
}

YSShuZu(stringOperator, multiplydivide, parentheses, intYunSFLen); //生成运算符

if (1==multiplydivide)
{
if (0 == remainder)
{
RemainderFouction(intNumC, stringOperator, intYunSFLen); //不能出现余数
int intInR;
MDOutput(intNumC, stringOperator, intYunSFLen,intPrintStyle);
dobResult = OperatorMD(intNumC, stringOperator, intYunSFLen);
outresult[shengchengshushu]=dobResult;
shengchengshushu=shengchengshushu+1;
}

if (1 == remainder)
{

MDOutput(intNumC, stringOperator, intYunSFLen,intPrintStyle);
dobResult = OperatorMD(intNumC, stringOperator, intYunSFLen);
dobResult = OperatorMD(intNumC, stringOperator, intYunSFLen);
outresult[shengchengshushu]=dobResult;
shengchengshushu=shengchengshushu+1;
}

}
if (0==multiplydivide)
{
minus_JiaJian(intNumA,stringOperator,min,max,minus,parentheses,intPrintStyle);
}
}
else //使用数组intNumA[100],intNumB[100]中的数进行真分数进行运算
{
calculate_ProperFraction(intNumA, intNumB, outI, min, max, intPrintStyle);
}
}

return 0;
}

}

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.math.BigDecimal" %>
<%@ page import="MyBean.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>在线答题系统</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

<style type="text/css">
body{
background-image: url(img/picture1.jpg);
background-repeat: repeat-y;
}
</style>

<script language="javascript">
function checkArray(){
if((form1.max.value-form1.min.value+1)<form1.count.value)
{
alert("数值范围输入错误,请重新输入数值范围(友情提示:数值范围应大于运算式的数量)!");
form1.min.value="";
form1.max.value="";
form1.count.value="";
form1.min.focus();
return false;
}
}
</script>

</head>

<body>
<font color=Green>
<center color="green">欢迎来到在线答题系统</center><br>
<center>请选择是否含有以下几种限制:
<form name="form1" action="" method="post" onSubmit="return checkArray()">
<table color=Green>
<tr>
<td style="color:#FF6600;">
<p>
真分数:
<select size="1" name="properfraction">
<option selected value="1">是</option>
<option value="0">否</option>
</seltct>
</p>
</td>
<td style="color:#FF6600;">
<p>
乘除法:
<select size="1" name="multiplydivide">
<option selected value="1">是</option>
<option value="0">否</option>
</seltct>
</p>
</td>
<td style="color:#FF6600;">
<p>
含余数:
<select size="1" name="remainder">
<option selected value="1">是</option>
<option value="0">否</option>
</seltct>
</p>
</td>
<td style="color:#FF6600;">
<p>
含负数:
<select size="1" name="minus">
<option selected value="1">是</option>
<option value="0">否</option>
</seltct>
</p>
</td>
<td style="color:#FF6600;">
<p>
含括号:
<select size="1" name="parentheses">
<option selected value="1">是</option>
<option value="0">否</option>
</seltct>
</p>
</td>
</tr>
<tr>
<td colspan="5" style="color:#FF6600;">
请输入数值范围:
<input type="text" name="min" size="5">-
<input type="text" name="max" size="5">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
请输入测试题数量:
<input type="text" name="count" size="8">
</td>
</tr>
<tr>
<td colspan="5" style="color:#FF6600;">
<center>
<input type="submit" value="提交"></input>
<input type="reset" value="重置"></input>
</center>
</td>
</tr>
</table>
</form>

<jsp:useBean id="jisuan" class="MyBean.JavaBean" scope="page"></jsp:useBean>

<jsp:setProperty property="*" name="jisuan"/>
<form action="JieRes.jsp" method="post">
<table>
<% jisuan.Operater(); %>
<% String shizhi[]=jisuan.getoutoperater();
double jieguo[]=jisuan.getoutresult();
int numm=jisuan.getCount();
int jihao=0;

session.setAttribute("chanshengshi", shizhi);
session.setAttribute("jieguosession", jieguo);
session.setAttribute("count", new Integer(numm));

String shurujieguo[]=new String[numm];

for(int i=0;i<jisuan.getCount();i++)
{
jihao=1;
shurujieguo[i]="name";
shurujieguo[i]=shurujieguo[i]+i;
BigDecimal b = new BigDecimal(jieguo[i]);
jieguo[i] = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
out.print("<tr><td style='color:#FF6600;'>"+shizhi[i]+"</td>");
%>
<td><input type="text" size="4" name=<%= shurujieguo[i] %>></td>
<%
out.print("</tr>");
}
%>
</table>
<%
if(jihao!=0)
{
out.print("<input type='submit' value='提交' align='bottom'>");
}
%>


</form>


</body>
</html>

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'JieRes.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

<style type="text/css">
body{
background-image: url(img/picture1.jpg);
background-repeat: repeat-x;
}
</style>

</head>

<body background="/img/picture1.jpg">
<center>
<table>
<%
Integer integer=(Integer)session.getAttribute("count");
int realnumber=integer.intValue();
double[] jieguojisuan=(double[])session.getAttribute("jieguosession");
String[] chanshengshis=(String[])session.getAttribute("chanshengshi");
//double[] jieguoshuru=(double[])session.getAttribute("shuruzhi");
String namee[]=new String[realnumber];

for(int i=0;i<realnumber;i++)
{
namee[i]="name";
namee[i]=namee[i]+i;
//out.println(jieguoshuru[i]);
String d=request.getParameter(namee[i]);
double dd=Double.parseDouble(d);
if(jieguojisuan[i]==dd)
{
out.print("<tr><td style='color:#FF6600;'>"+chanshengshis[i]+"</td><td style='color:#FF6600;'>"+jieguojisuan[i]+"</td><td style='color:#FF6600;'>正确</td></tr>");
}
else
{
out.print("<tr><td style='color:#FF6600;'>"+chanshengshis[i]+"</td><td style='color:#FF6600;'>"+jieguojisuan[i]+"</td><td style='color:#FF6600;'>错误</td></tr>");
}
}
%>
</table>
</center>
<a href="index.jsp" style=color:#FF6600;><center>返回出题界面</center></a>
</body>
</html>

原文地址:https://www.cnblogs.com/ming123/p/6686435.html