四则运算网页版

      

1.结对开发成员:刘子伦、康杨

2.设计思想:

javabean里写四则运算出题的核心代码。出题的java代码在以前的博客里。因为要写网页版,先设置一个首页MyHtml.html,然后通过一个按钮,从MyHtml.html跳转到NewFile.html页面。这个页面编写为出题页面,页面里面有数值范围、题目个数和题目类型。然后提交跳转到NewFile.jsp页面,这个页面编写为答题页面,里面有题目输入答案,答完题目以后点击提交跳转到MyFile.jsp。这个页面里面显示答题是否正确和正确结果。

3.程序源代码

MyHtml.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>

   <style type="text/css">
body 
{
background-image:url(5.jpg);
background-size:100%;
}//设置背景图片
</style>
<body>
 <center>
  <h1>欢迎使用四则运算答题系统<h1>
 
  <center>
    <td align="center">
 <form action="MyHtml.html" method="post">
 <center>

 <input type="submit"  name="submit" style="text-align:center,vertical-align:middle;width:400px;height:70px;font-size:20px" value="我已准备好,请开始出题"  onClick="window.location.href='NewFile.html'">
<input type="submit"  name="submit" style="text-align:center,vertical-align:middle;width:400px;height:70px;font-size:20px" value="我没准备好,退出系统" onClick="window.close()";>
</div></form>
</td>
</center>
   
<div id="jnkc">
 
</div>
 
<script>setInterval("jnkc.innerHTML=new Date().toLocaleString()+' 星期'+'日一二三四五六'.charAt(new Date().getDay());",1000);
 
</script>
    
</body>
</html>

  NewFile.html

<!DOCTYPE html>
  <html>
    <head>
      <title>四则运算</title>
      <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
      <meta name="keywords" content="keyword1,keyword2,keyword3">
      <meta name="description" content="this is my page">
     
      
     <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
 
   </head>   
<style type="text/css">
body 
{
background-image:url(2.jpg);
background-size:100%;
}//设置背景图片
</style>
  
    <script type="text/javascript">
        
        function tick() {
            var today;
            today = new Date();
            document.getElementById("localtime").innerHTML = showLocale(today);
            window.setTimeout("tick()", 1000);
        }
        tick();
    </script>
    <br />
    <h1 align="center">题目选择</h1>
   <!-- 传递参数的值给NewFile.jsp处理 -->
   <form action="NewFile.jsp" method="post">  
   <!-- 互斥选择,值只能有一个 -->
   <center>
   <p><br>
     请输入最大值:<input type="value" name="TopNumber"><br>
     <br>
     请输入最小值:<input type="value" name="BaseNumber">
     <br>   
     <br> 
     请输入题目个数:
     <input type="text" name="timugeshu">
   </p>
   <p>题目类型:     <br>
   </p>
   <tr> 请选择需要题型是否有乘除法:
     <input type="radio" name="xuanze" value=1>√
   <input type="radio" name="xuanze" value=2>×
 </tr>
   <br>
   <tr>请选择需要的题型是否有余数:
   <input type="radio" name="xuanze1" value=3>√
   <input type="radio" name="xuanze1" value=4>×
   </tr>
   <br>
   <tr>请选择需要的题型是否有括号:
   <input type="radio" name="xuanze2" value=5>√
   <input type="radio" name="xuanze2" value=6>×</tr>
   <br>
   <br>
   
   <input type="submit" name="submit" value="提交">
   </center>

   </form>
   </body>
 </html>

  NewFile.jsp

<%@ page language="java" contentType="text/html; charset=utf-8" 
     pageEncoding="utf-8"%>
  <%@ page import="szys.*"%>
  <%
  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>
   <script type="text/javascript">
var c=0
var t
function timedCount()
{
document.getElementById('txt').value=c
c=c+1
t=setTimeout("timedCount()",1000)
}

function stopCount()
{
c=0;
setTimeout("document.getElementById('txt').value=0",0);
clearTimeout(t);
}
</script>
   
     <base href="<%=basePath%>">     
     <title>四则运算</title>
     <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
          <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">
     -->
     
   </head>   
<style type="text/css">
body 
{
background-image:url(3.jpg);
background-size:100%;
}//设置背景图片
</style>
       

    <%
    int timugeshu=Integer.parseInt((String)request.getParameter("timugeshu"));
    String[] s=new String[timugeshu];
    float k[]=new float[timugeshu];
    math a=new math();
    request.setCharacterEncoding("UTF-8");
    String xuanze = request.getParameter("xuanze");
    String xuanze1 = request.getParameter("xuanze1");
    String xuanze2 = request.getParameter("xuanze2");
    String TopNumber,BaseNumber;
    TopNumber=request.getParameter("TopNumber");
    BaseNumber=request.getParameter("BaseNumber");
    a.SetValue(a.StrToNum(TopNumber),a.StrToNum(BaseNumber));
    if(xuanze!=null&&xuanze1!=null&&xuanze2!=null){
    if(xuanze.equals("1"))
    {
          a.SetValue1(1);
    }
    if(xuanze1.equals("3"))
    {
           a.SetValue2(1);
    }
    if(xuanze2.equals("5"))
    {
          a.SetValue3(1);
    }
 }
     %>
    <form action="MyFile.jsp" method="post">
    <center>
    <%
      a.main();
      float temp;
      String[] se=new String[timugeshu];
      for(int i=0;i<timugeshu;i++){
      s[i]=a.cs(i);
      se[i]="name";
      se[i]=se[i]+i;
      k[i]=a.css(i);
      out.print(s[i]);
     
      
    %>   
   <input type="text" style="color: blue;width:50px;height:21px;" name=<%=se[i] %>>
  <% out.print("&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp"); %>
   <% 
   if((i+1)%3==0)
         out.print("<br><br>");%>
    <%
        } 
         session.setAttribute( "v1",s);
         session.setAttribute( "v2",k); 
     %>
      </center>
         
     
         <center>
     <br><input type="submit" name="submit" value="提交">   
     <input type="hidden" name="timugeshu" value="<%=timugeshu %>"> 
     <input type="button" value="开始计时!" onClick="timedCount()">
      <input type="text" id="txt">
     <input type="button" value="停止计时!" onClick="stopCount()">   
     <%    %>
      </center>
   </form>
  
      
   
    
     
   </body>
 </html>

  MyFile.jsp

<%@ page language="java" import="java.util.*" pageEncoding="gb2312" contentType="text/html; charset=gb2312"%>
<%@ page import="szys.*"%>
<%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">
     --> 
   </head>
   <style type="text/css">
body 
{
background-image:url(4.jpg);
background-size:100%;
}//设置背景图片
</style>
   <% request.setCharacterEncoding("UTF-8");%> 
   <center>
   <%  
     int timugeshu=Integer.parseInt((String)request.getParameter("timugeshu"));
     String[] name=new String[timugeshu];
     String[] sum=new String[timugeshu];
     math a=new math();
     float sum1[]=new float[timugeshu];
     int right=0;
     String[] s= (String[])session.getAttribute("v1");
     float[] k=(float[])session.getAttribute("v2");
     
     for(int i=0;i<timugeshu;i++)
         sum1[i]=0;
     for(int i=0;i<timugeshu;i++){
         name[i]="name";
         name[i]=name[i]+i;         
         sum[i]=request.getParameter(name[i]);
         out.print(s[i]);
         out.print("<tr>"+sum[i]+"</tr>");
         if(sum[i]=="")
            out.print("未回答!");
         else{
             if(((int)(k[i]*100))%100!=0)
                sum1[i]=a.StrToFloat1(sum[i]);
             else
                sum1[i]=a.StrToFloat(sum[i]);
             if(Math.abs(sum1[i]*100-k[i]*100)<4){
                out.print(" 回答正确!");
                right++;
             }
             else
                out.print(" 回答错误,正确答案是: "+k[i]);
         }   
         
          out.println("<br>");
     }
     out.print("总共做对 "+right+" 题");
     

   %><br>
    <input type="button" value="返回首页" onClick="window.location.href='MyHtml.html'">
    <input type="button" value="关闭" onClick="window.close();">
     </center>
   </body>
 </html>

  

package Calculator;
import java.util.*;
import Calculator.arithmetic;
import Calculator.subject;
import Calculator.Formula;
import java.lang.*;

public class calculator {
    static int N=100;
    //public int length = 0;//运算数个数
    static int fuh;//表示运算符的数(0、1、2、3分别代表+、-、*、/)
    static subject sub[]=new subject[N];//所有算式
    static int lpoint1;//内层左括号的位置
    static int rpoint1;//内层右括号的位置
    static int lpoint2;//外层左括号的位置
    static int rpoint2;//外层右括号的位置
    static Formula Formul[]=new Formula[N];    //定义一个字符串数组
    static int Flength;    //字符串数组长度
    static int i, j;
    static int Result;    //算式的运算结果
    static int dataS[]=new int[N];    //存储算式中的数
    static String fuhaoS[]=new String[N];    //存储算式中的符号
    static int count;    //记录答对题数
    static int CountNum=-1;    //记录对每道题求解
    static int CountStr=-1;    //记录每道题
    static int low;    //算式数值范围的最小值
    static int high;    //算式数值范围的最大值
    static int MulAndDiv;   //是否有乘除
    static int Bracket;     //是否有括号
    static int Negative;       //是否有负数
    static int Remainder;       //是否有余数
    //static int IsRep;       //是否重复
    static int Results[]= new int[N];      //正确结果数组
    //public subject buffer[] = new subject[N];     //缓冲区数组
    static String buffer[]=new String[N];
    static int LENGTH[]=new int[N];        //记录算式的长度
    static int number;    //题目数量
    //将算式转化为string数组
    public void ToString(int geti, int length)
    {
        Flength = -1;
        for (j = 0; j < length; j++)
        {
            if (sub[geti].arith[j].left2 != "")
            {
                Flength =Flength+ 1;
                Formul[Flength].str = sub[geti].arith[j].left2;
            }
            if (sub[geti].arith[j].left1 != "")
            {
                Flength =Flength+ 1;
                Formul[Flength].str = sub[geti].arith[j].left1;
            }
            Flength =Flength+ 1;
            Formul[Flength].str = String.valueOf(sub[geti].arith[j].member);
            Formul[Flength].data = sub[geti].arith[j].member;
            if (sub[geti].arith[j].right1 != "")
            {
                Flength =Flength+ 1;
                Formul[Flength].str = sub[geti].arith[j].right1;
            }
            if (sub[geti].arith[j].right2 != "")
            {
                Flength =Flength+ 1;
                Formul[Flength].str = sub[geti].arith[j].right2;
            }
            if (sub[geti].arith[j].fuhao != "")
            {
                Flength =Flength+ 1;
                Formul[Flength].str = sub[geti].arith[j].fuhao;
            }
        }
        String bstr="";
        for(i=0;i<Flength;i++)
        {
            bstr=bstr+Formul[i].str;
        }
        CountStr+=1;
        buffer[CountStr]=bstr;
    }
    
    //比较优先级
    public String Precede(String Fuhao1, String Fuhao2)
    {
        String FuResult="";    //返回优先级关系">"、"<"、"="
        if (Fuhao1 == "+")
        {
            if (Fuhao2 == "+" || Fuhao2 == "-" || Fuhao2 == ")" || Fuhao2 == "#")
            {
                FuResult = ">";
            }
            else
            {
                FuResult = "<";
            }
        }
        if (Fuhao1 == "-")
        {
            if (Fuhao2 == "+" || Fuhao2 == "-" || Fuhao2 == ")" || Fuhao2 == "#")
            {
                FuResult = ">";
            }
            else
            {
                FuResult = "<";
            }
        }
        if (Fuhao1 == "*")
        {
            if (Fuhao2 == "(")
            {
                FuResult = "<";
            }
            else
            {
                FuResult = ">";
            }
        }
        if (Fuhao1 == "/")
        {
            if (Fuhao2 == "(")
            {
                FuResult = "<";
            }
            else
            {
                FuResult = ">";
            }
        }
        if (Fuhao1 == "(")
        {
            if (Fuhao2 == ")")
            {
                FuResult = "=";
            }
            else
            {
                FuResult = "<";
            }
        }
        if (Fuhao1 == ")")
        {
            FuResult = ">";
        }
        if (Fuhao1 == "#")
        {
            if (Fuhao2 == "#")
            {
                FuResult = "=";
            }
            else
            {
                FuResult = "<";
            }
        }
        return FuResult;
    }
    
    //两个数运算
    public int Operate(int num1, String theta, int num2)
    {
        int InResult;    //返回运算结果
        if (theta == "+")
        {
            InResult = num1 + num2;
        }
        else if (theta == "-")
        {
            InResult = num1 - num2;
        }
        else if (theta == "*")
        {
            InResult = num1*num2;
        }
        else
        {
            InResult = num1 / num2;
        }
        return InResult;
    }
    
    //表达式求值
    public int ValueResult(int geti, int length)
    {
        int i;
        Flength = 0;
        String PResult;    //优先级比较结果
        String theta;    //出栈符号
        int num1, num2;    //出栈运算数
        int dalength=0;    //算式数据数组的长度
        int fulength=0;    //算式符号数组的长度
        ToString(geti, length);
        
        Formul[Flength].str = "#";
        //InitStack(OPND);
        //fuInitStack(OPTR);
        //fuPush(OPTR, "#");
        fuhaoS[fulength]="#";
        
        for (i = 0; i <= Flength; i++)
        {
            if (Formul[i].str == "#")
            {
                while (fuhaoS[fulength]!= "#")
                {
                    PResult = Precede(fuhaoS[fulength], Formul[i].str);
                    if (PResult == ">")
                    {
                        //fuPop(OPTR, theta);
                        theta=fuhaoS[fulength];
                        fulength-=1;
                        //Pop(OPND, num2);
                        num2=dataS[dalength];
                        dalength-=1;
                        //Pop(OPND, num1);
                        num1=dataS[dalength];
                        dalength-=1;
                        int num3 = Operate(num1, theta, num2);
                        //Push(OPND, num3);
                        dalength+=1;
                        dataS[dalength]=num3;
                    }
                    else if (PResult == "<")
                    {
                        //fuPush(OPTR, Formul[i].str);
                        fulength+=1;
                        fuhaoS[fulength]=Formul[i].str;
                    }
                    else
                    {
                        //fuPop(OPTR, theta);
                        theta=fuhaoS[fulength];
                        fulength-=1;
                    }
                }
            }
            else if (Formul[i].str == "(" || Formul[i].str == ")" || Formul[i].str == "+" || Formul[i].str == "-" || Formul[i].str == "*" || Formul[i].str == "/")
            {
                PResult = Precede(fuhaoS[fulength], Formul[i].str);
                if (PResult == ">")
                {
                    //fuPop(OPTR, theta);
                    theta=fuhaoS[fulength];
                    fulength-=1;
                    //Pop(OPND, num2);
                    num2=dataS[dalength];
                    dalength-=1;
                    //Pop(OPND, num1);
                    num1=dataS[dalength];
                    dalength-=1;
                    int num3 = Operate(num1, theta, num2);
                    //Push(OPND, num3);
                    dalength+=1;
                    dataS[dalength]=num3;
                    PResult = Precede(fuhaoS[fulength], Formul[i].str);
                    if (PResult == "=")
                    {
                        //fuPop(OPTR, theta); continue;
                        theta=fuhaoS[fulength];
                        fulength-=1;continue;
                    }
                    else
                    {
                        //fuPush(OPTR, Formul[i].str);
                        fulength+=1;
                        fuhaoS[fulength]=Formul[i].str;
                    }
                }
                else if (PResult == "<")
                {
                    //fuPush(OPTR, Formul[i].str);
                    fulength+=1;
                    fuhaoS[fulength]=Formul[i].str;
                }
                else
                {
                    //fuPop(OPTR, theta);
                    theta=fuhaoS[fulength];
                    fulength-=1;
                }
            }
            else
            {
                //Push(OPND, Formul[i].data);
                dalength+=1;
                dataS[dalength]=Formul[i].data;
            }
        }
        return dataS[dalength];
    }
    
    //随机数产生运算符
    String Fuhao(int fuh)
    {
        String fuh0;//返回运算符号
        if (fuh == 0)
            fuh0 = "+";
        else if (fuh == 1)
            fuh0 = "-";
        else if (fuh == 2)
            fuh0 = "*";
        else
            fuh0 = "/";
        return fuh0;
    }
    
    //初始化算式
    public void Init(int geti,int length, int high, int low, int TwoOrFour)
    {
        Random rand = new Random();
        for (j = 0; j < length - 1; j++)
        {
            sub[geti].arith[j].left2 = "";
            sub[geti].arith[j].left1 = "";
            sub[geti].arith[j].right1 = "";
            sub[geti].arith[j].right2 = "";
            sub[geti].arith[j].member = rand.nextInt() % (high - low) + low;
            //无乘除法
            if (TwoOrFour == 2)
            {
                fuh = rand.nextInt() % 2;
            }
            //有乘除法
            if (TwoOrFour == 4)
            {
                fuh = rand.nextInt() % 4;
            }
            sub[geti].arith[j].fuhao = Fuhao(fuh);
        }
        sub[geti].arith[length - 1].left2 = "";
        sub[geti].arith[length - 1].left1 = "";
        sub[geti].arith[length - 1].right1 = "";
        sub[geti].arith[length - 1].right2 = "";
        sub[geti].arith[length - 1].member = rand.nextInt() % (high - low) + low;
        sub[geti].arith[length - 1].fuhao = "=";
        for (j = 0; j < length; j++)
        {
            if (sub[geti].arith[j].right1 == "" || sub[geti].arith[j].right1 == ")")
            {
                if (sub[geti].arith[j].fuhao == "/"&&sub[geti].arith[j].left2 == ""&&sub[geti].arith[j].left1 == ""&&sub[geti].arith[j].right2 == "")
                {
                    if (sub[geti].arith[j + 1].fuhao == "/"&&sub[geti].arith[j + 1].left2 == ""&&sub[geti].arith[j + 1].left1 == ""&&sub[geti].arith[j + 1].right1 == ""&&sub[geti].arith[j + 1].right2 == "")
                    {
                        sub[geti].arith[j].left1 = "(";
                        sub[geti].arith[j + 1].right1 = ")";
                        j +=1;
                    }
                }
            }
        }
    }
    /*
    //输出函数
    public void Output(int geti, int length)
    {
        for (j = 0; j < length; j++)
        {
            //cout << sub.arith[j].left2 << sub.arith[j].left1 << sub.arith[j].member << sub.arith[j].right1 << sub.arith[j].right2 << sub.arith[j].fuhao;
            System.out.print(sub[geti].arith[j].left2);
            System.out.print(sub[geti].arith[j].left1);
            System.out.println(sub[geti].arith[j].member);
            System.out.print(sub[geti].arith[j].right1);
            System.out.print(sub[geti].arith[j].right2);
            System.out.print(sub[geti].arith[j].fuhao);
        }
        //cout << endl;
    }
    */
    //括号的产生
    public int Bracket(int geti, int length)
    {
        Random rand = new Random();
        int check = 0;
        if (length > 2)
        {
            int floor = rand.nextInt() % 2 + 1;//产生括号的层数
            if (floor == 1)
            {
                lpoint1 = rand.nextInt() % (length - 1);//产生左括号的位置
                rpoint1 = lpoint1 + rand.nextInt() % (length - 1 - lpoint1);//产生右括号的位置
                if (lpoint1 == rpoint1)
                {
                    if (lpoint1 > 0)
                    {
                        lpoint1 -= 1;
                    }
                    else
                    {
                        if (rpoint1 < length - 1)
                        {
                            rpoint1 +=1;
                        }
                    }
                }
                sub[geti].arith[lpoint1].left1 = "(";
                sub[geti].arith[rpoint1].right1 = ")";
            }
            else
            {
                if (length > 3)
                {
                    lpoint1 = rand.nextInt() % (length - 1);//产生内层左括号的位置
                    rpoint1 = lpoint1 + rand.nextInt() % (length - 1 - lpoint1);//产生内层右括号的位置
                    if (lpoint1 == rpoint1)
                    {
                        if (lpoint1 > 0)
                        {
                            lpoint1 -= 1;
                        }
                        else
                        {
                            if (rpoint1 < length - 1)
                            {
                                rpoint1 +=1;
                            }
                        }
                    }
                    sub[geti].arith[lpoint1].left1 = "(";
                    sub[geti].arith[rpoint1].right1 = ")";
                    if (lpoint1 == 0)
                    {
                        lpoint2 = lpoint1;//产生外层左括号的位置
                    }
                    else
                    {
                        lpoint2 = lpoint1 - rand.nextInt() % lpoint1;//产生外层左括号的位置
                    }
                    rpoint2 = rpoint1 + rand.nextInt() % (length - rpoint1);//产生外层右括号的位置
                    if (lpoint2 == lpoint1&&rpoint2 == rpoint1)
                    {
                        if (lpoint2 > 0)
                        {
                            lpoint2 -= 1;
                        }
                        else
                        {
                            if (rpoint2 < length - 1)
                            {
                                rpoint2 +=1;
                            }
                        }
                    }
                    sub[geti].arith[lpoint2].left2 = "(";
                    sub[geti].arith[rpoint2].right2 = ")";
                }
                else
                {
                    check = 1;
                }
            }
        }
        return check;
    }

    //判断用户是否答对
    public int Right(int result, int answer)
    {
        if (answer == result)
        {
            return 0;
        }
        else
        {
            return 1;
        }
        //return 0;
    }

    //验证除法有无余数
    public int change(int geti, int length)
    {
        int check = 0;
        for (j = 0; j < length; j++)
        {
            if (sub[geti].arith[j].fuhao == "/"&&sub[geti].arith[j].right1 != ")")
            {
                if (sub[geti].arith[j].member%sub[geti].arith[j + 1].member != 0)
                {
                    check = 1;
                }
            }
            if (sub[geti].arith[j].fuhao == "/"&&sub[geti].arith[j].right1 == ")")
            {
                if ((sub[geti].arith[j - 1].member / sub[geti].arith[j].member) % sub[geti].arith[j + 1].member != 0)
                {
                    check = 1;
                }
            }
        }
        return check;
    }

    //有乘除法、有括号、加减有负数、除法有余数
    public void Output1(int number, int low, int high)
    {
        int count = 0;
        for (i = 0; i < number; i++)
        {
            int check = 0;//检验产生式是否合格
            Random rand = new Random();
            sub[i].length = rand.nextInt() % 9 + 2;
            Init(i, sub[i].length, high, low, 4);
            Result = ValueResult(i, sub[i].length);
            check = Bracket(i, sub[i].length);
            if (Result>high)
            {
                check = 1;
            }
            if (check == 1)
            {
                i = i - 1; continue;
            }
            else
            {
                //Output(sub[i], sub[i].length);
                //LENGTH[CountNum++]=sub[i].length;
                //buffer[CountNum++]=sub[i];
                CountNum+=1;
                Results[CountNum]=Result;
                //int answer = Input();
                //Right(Result, answer);
            }
        }
        //UserResult(count);
    }
    //有乘除法、有括号、加减有负数、除法无余数
    public void Output2(int number, int low, int high)
    {
        int count = 0;
        for (i = 0; i < number; i++)
        {
            int check = 0;//检验产生式是否合格
            Random rand = new Random();
            sub[i].length = rand.nextInt() % 9 + 2;
            int check1 = 0;//检验除法是否有余数
            Init(i, sub[i].length, high, low, 4);
            check = Bracket(i, sub[i].length);
            check1 = change(i, sub[i].length);
            Result = ValueResult(i, sub[i].length);
            if (Result > high)
            {
                check = 1;
            }
            if (check == 1 || check1 == 1)
            {
                i = i - 1; continue;
            }
            else
            {
                //Output(sub[i], sub[i].length);
                //LENGTH[CountNum++]=sub[i].length;
                //buffer[CountNum++]=sub[i];
                CountNum+=1;
                Results[CountNum]=Result;
                //int answer = Input();
                //Right(Result, answer);
            }
        }
        //UserResult(count);
    }
    //有乘除法、有括号、加减无负数、除法有余数
    public void Output3(int number, int low, int high)
    {
        int count = 0;
        for (i = 0; i < number; i++)
        {
            int check = 0;//检验产生式是否合格
            Random rand = new Random();
            sub[i].length = rand.nextInt() % 9 + 2;
            Init(i, sub[i].length, high, low, 4);
            check = Bracket(i, sub[i].length);
            Result = ValueResult(i, sub[i].length);
            if (Result < 0 || Result > high)
            {
                check = 1;
            }
            if (check == 1)
            {
                i = i - 1; continue;
            }
            else
            {
                //Output(sub[i], sub[i].length);
                //LENGTH[CountNum++]=sub[i].length;
                //buffer[CountNum++]=sub[i];
                CountNum+=1;
                Results[CountNum]=Result;
                //int answer = Input();
                //Right(Result, answer);
            }
        }
        //UserResult(count);
    }
    //有乘除法、有括号、加减无负数、除法无余数
    public void Output4(int number, int low, int high)
    {
        int count = 0;
        for (i = 0; i < number; i++)
        {
            int check = 0;//检验产生式是否合格
            int check1 = 0;//检验除法是否有余数
            Random rand = new Random();
            sub[i].length = rand.nextInt() % 9 + 2;
            Init(i, sub[i].length, high, low, 4);
            check = Bracket(i, sub[i].length);
            check1 = change(i, sub[i].length);
            Result = ValueResult(i, sub[i].length);
            if (Result < 0 || Result > high)
            {
                check = 1;
            }
            if (check == 1 || check1 == 1)
            {
                i = i - 1; continue;
            }
            else
            {
                //Output(sub[i], sub[i].length);
                //LENGTH[CountNum++]=sub[i].length;
                //buffer[CountNum++]=sub[i];
                CountNum+=1;
                Results[CountNum]=Result;
                //int answer = Input();
                //Right(Result, answer);
            }
        }
        //UserResult(count);
    }
    //有乘除法、无括号、加减有负数、除法有余数
    public void Output5(int number, int low, int high)
    {
        int count = 0;
        for (i = 0; i < number; i++)
        {
            int check = 0;
            Random rand = new Random();
            sub[i].length = rand.nextInt() % 9 + 2;
            Init(i, sub[i].length, high, low, 4);
            Result = ValueResult(i, sub[i].length);
            if (Result > high)
            {
                check = 1;
            }
            if (check == 1)
            {
                i = i - 1; continue;
            }
            //Output(sub[i], sub[i].length);
            //LENGTH[CountNum++]=sub[i].length;
            //buffer[CountNum++]=sub[i];
            CountNum+=1;
            Results[CountNum]=Result;
            //int answer = Input();
            //Right(Result, answer);
        }
        //UserResult(count);
    }
    //有乘除法、无括号、加减有负数、除法无余数
    public void Output6(int number, int low, int high)
    {
        int count = 0;
        for (i = 0; i < number; i++)
        {
            int check = 0;
            Random rand = new Random();
            sub[i].length = rand.nextInt() % 9 + 2;
            Init(i, sub[i].length, high, low, 4);
            check = change(i, sub[i].length);
            Result = ValueResult(i, sub[i].length);
            if (Result > high)
            {
                check = 1;
            }
            if (check == 1)
            {
                i = i - 1; continue;
            }
            //Output(sub[i], sub[i].length);
            //LENGTH[CountNum++]=sub[i].length;
            //buffer[CountNum++]=sub[i];
            CountNum+=1;
            Results[CountNum]=Result;
            //int answer = Input();
            //Right(Result, answer);
        }
        //UserResult(count);
    }
    //有乘除法、无括号、加减无负数、除法有余数
    public void Output7(int number, int low, int high)
    {
        int count = 0;
        for (i = 0; i < number; i++)
        {
            int check = 0;//检验
            Random rand = new Random();
            sub[i].length = rand.nextInt() % 9 + 2;
            Init(i, sub[i].length, high, low, 4);
            Result = ValueResult(i, sub[i].length);
            if (Result < 0 || Result > high)
            {
                check = 1;
            }
            if (check == 1)
            {
                i = i - 1;
            }
            else
            {
                //Output(sub[i], sub[i].length);
                //LENGTH[CountNum++]=sub[i].length;
                //buffer[CountNum++]=sub[i];
                CountNum+=1;
                Results[CountNum]=Result;
                //int answer = Input();
                //Right(Result, answer);
            }
        }
        //UserResult(count);
    }
    //有乘除法、无括号、加减无负数、除法无余数
    public void Output8(int number, int low, int high)
    {
        int count = 0;
        for (i = 0; i < number; i++)
        {
            int check = 0;//检验
            Random rand = new Random();
            sub[i].length = rand.nextInt() % 9 + 2;
            Init(i, sub[i].length, high, low, 4);
            Result = ValueResult(i, sub[i].length);
            check = change(i, sub[i].length);
            if (Result < 0 || Result > high)
            {
                check = 1;
            }
            if (check == 1)
            {
                i = i - 1; continue;
            }
            else
            {
                //Output(sub[i], sub[i].length);
                //LENGTH[CountNum++]=sub[i].length;
                //buffer[CountNum++]=sub[i];
                CountNum+=1;
                Results[CountNum]=Result;
                //int answer = Input();
                //Right(Result, answer);
            }
        }
        //UserResult(count);
    }
    //无乘除法、有括号、加减有负数
    public void Output9(int number, int low, int high)
    {
        int count = 0;
        for (i = 0; i < number; i++)
        {
            int check = 0;//检验产生式是否合格
            Random rand = new Random();
            sub[i].length = rand.nextInt() % 9 + 2;
            Init(i, sub[i].length, high, low, 2);
            Result = ValueResult(i, sub[i].length);
            check = Bracket(i, sub[i].length);
            if (Result>high)
            {
                check = 1;
            }
            if (check == 1)
            {
                i = i - 1; continue;
            }
            else
            {
                //Output(sub[i], sub[i].length);
                //LENGTH[CountNum++]=sub[i].length;
                //buffer[CountNum++]=sub[i];
                CountNum+=1;
                Results[CountNum]=Result;
                //int answer = Input();
                //Right(Result, answer);
            }
        }
        //UserResult(count);
    }
    //无乘除法、有括号、加减无负数
    public void Output10(int number, int low, int high)
    {
        int count = 0;
        for (i = 0; i < number; i++)
        {
            int check = 0;//检验产生式是否合格
            Random rand = new Random();
            sub[i].length = rand.nextInt() % 9 + 2;
            Init(i, sub[i].length, high, low, 2);
            check = Bracket(i, sub[i].length);
            Result = ValueResult(i, sub[i].length);
            if (Result < 0 || Result > high)
            {
                check = 1;
            }
            if (check == 1)
            {
                i = i - 1; continue;
            }
            else
            {
                //Output(sub[i], sub[i].length);
                //LENGTH[CountNum++]=sub[i].length;
                //buffer[CountNum++]=sub[i];
                CountNum+=1;
                Results[CountNum]=Result;
                //int answer = Input();
                //Right(Result, answer);
            }
        }
        //UserResult(count);
    }
    //无乘除法、无括号、加减有负数
    public void Output11(int number, int low, int high)
    {
        int count = 0;
        for (i = 0; i < number; i++)
        {
            Random rand = new Random();
            sub[i].length = rand.nextInt() % 9 + 2;
            Init(i, sub[i].length, high, low, 2);
            Result = ValueResult(i, sub[i].length);
            if (Result>high)
            {
                i = i - 1; continue;
            }
            //Output(sub[i], sub[i].length);
            //LENGTH[CountNum++]=sub[i].length;
            //buffer[CountNum++]=sub[i];
            CountNum+=1;
            Results[CountNum]=Result;
            //int answer = Input();
            //Right(Result, answer);
        }
        //UserResult(count);
    }
    //无乘除法、无括号、加减无负数
    public void Output12(int number, int low, int high)
    {
        //int count = 0;//记录用户答对题数
        for (i = 0; i < number; i++)
        {
            Random rand = new Random();
            sub[i].length = rand.nextInt() % 9 + 2;
            Init(i, sub[i].length, high, low, 2);
            int check = 0;//检验
            Result = ValueResult(i, sub[i].length);
            if (Result<0 || Result>high)
            {
                check = 1;
            }
            if (check == 1)
            {
                i = i - 1; continue;
            }
            //Output(sub[i], sub[i].length);
            //LENGTH[CountNum++]=sub[i].length;
            //buffer[CountNum++]=sub[i];
            CountNum+=1;
            Results[CountNum]=Result;
            //int answer = Input();
            //Right(Result, answer);
        }
        //UserResult(count);
    }
    
    public void SetValue(int high1,int low1,int number1){
        MulAndDiv=0;
        Bracket=0;
        Negative=0;
        Remainder=0;
        high=high1;
        low=low1;   
        number=number1;
    } 
    public void SetValue1(int MAD)
    {
        MulAndDiv=MAD;
    }
    public void SetValue2(int Bra)
    {
        Bracket=Bra;
    }
    public void SetValue3(int Neg)
    {
        Negative=Neg;
    }
    public void SetValue4(int Rem)
    {
        Remainder=Rem;
    }
    
    public int Choose(){
        if(MulAndDiv==1&&Bracket==1&&Negative==1&&Remainder==1){
            return 1;
        }
        else if(MulAndDiv==1&&Bracket==1&&Negative==1&&Remainder==0){
            return 2;
        }
        else if(MulAndDiv==1&&Bracket==1&&Negative==0&&Remainder==1){
            return 3;
        }
        else if(MulAndDiv==1&&Bracket==1&&Negative==0&&Remainder==0){
            return 4;
        }
        else if(MulAndDiv==1&&Bracket==0&&Negative==1&&Remainder==1){
            return 5;
        }
        else if(MulAndDiv==1&&Bracket==0&&Negative==1&&Remainder==0){
            return 6;
        }
        else if(MulAndDiv==1&&Bracket==0&&Negative==0&&Remainder==1){
            return 7;
        }
        else if(MulAndDiv==1&&Bracket==0&&Negative==0&&Remainder==0){
            return 8;
        }
        else if(MulAndDiv==0&&Bracket==1&&Negative==1&&Remainder==0){
            return 9;
        }
        else if(MulAndDiv==0&&Bracket==1&&Negative==0&&Remainder==0){
            return 10;
        }
        else if(MulAndDiv==0&&Bracket==0&&Negative==1&&Remainder==0){
            return 11;
        }
        else
            return 12;
    }
    
     public int StrToNum(String strget)
     {
         int num=0;
         for(int i=0;i<strget.length();i++)
         {
             num=num*10+strget.charAt(i)-48;
         }
         return num;
     }
     //输出算式
     public String OutputEq(int number1)
     {
         return buffer[number1];
     }
     //输出答案
     public int OutputAn(int number1)
     {
         return Results[number1];
     }
     public int OutputLE(int number1)
     {
         return LENGTH[number1];
     }

    public int main()
    {
        int chooseWay;    //条件筛选结果
        chooseWay = Choose();        //条件筛选
        switch (chooseWay)
        {
        case 1:Output1(number, low, high); break;
        case 2:Output2(number, low, high); break;
        case 3:Output3(number, low, high); break;
        case 4:Output4(number, low, high); break;
        case 5:Output5(number, low, high); break;
        case 6:Output6(number, low, high); break;
        case 7:Output7(number, low, high); break;
        case 8:Output8(number, low, high); break;
        case 9:Output9(number, low, high); break;
        case 10:Output10(number, low, high); break;
        case 11:Output11(number, low, high); break;
        case 12:Output12(number, low, high);
        }
        return 0;
    }
    
}

  4.运行结果截图

 

 

 

5.总结体会

通过本次编程,我们更加熟悉了JAVA程序的编写,并进一步熟悉了eclipse环境下程序的运行,编程过程中遇到了一些 问题,例如各个函数都没有问题。我们这次做出来的网页效果与我们想象的差距还很大,有着很多的预想功能都没有实现。我们需要更加努力的学习javaweb的用法。在这次制作过程中,我们由于能力有限,未能够连接上数据库,还需要再往后的学习过程中更加努力,多查阅资料,多动手尝试,争取连接上数据库,并进行增删改查的功能实现。

 

6.psp表

估计各个模块需要的时间

 

PSP2.1

Personal Software Process Stages

Time

Planning

计划

 

  · Estimate

  · 估计这个任务需要多少时间

 24h

Development

开发

 

  · Analysis

  · 需求分析 (包括学习新技术)

5h

 

  · Design Spec

  · 生成设计文档

 2h

  · Design Review

  · 设计复审 (和同事审核设计文档)

 1h

  · Coding Standard

  · 代码规范 (为目前的开发制定合适的规范)

 1h

  · Design

  · 具体设计

 3h

  · Coding

  · 具体编码

 8h

  · Code Review

  · 代码复审

 2h

  · Test

  · 测试(自我测试,修改代码,提交修改)

 4h

Reporting

报告

 

  · Test Report

  · 测试报告

 1h

  · Size Measurement

  · 计算工作量

 1h

  · Postmortem & Process Improvement Plan

  · 事后总结, 并提出过程改进计划

 1h

 

合计

 28h

 

各个模块实际需要的时间

PSP2.1

Personal Software Process Stages

Time

Planning

计划

 

  · Estimate

  · 估计这个任务需要多少时间

 20h

Development

开发

 

  · Analysis

  · 需求分析 (包括学习新技术)

5h

 

  · Design Spec

  · 生成设计文档

 1h30min

  · Design Review

  · 设计复审 (和同事审核设计文档)

 30min

  · Coding Standard

  · 代码规范 (为目前的开发制定合适的规范)

 1h

  · Design

  · 具体设计

 1h30min

  · Coding

  · 具体编码

 10h

  · Code Review

  · 代码复审

 1h

  · Test

  · 测试(自我测试,修改代码,提交修改)

 1h30min

Reporting

报告

 

  · Test Report

  · 测试报告

 1h

  · Size Measurement

  · 计算工作量

 1h

  · Postmortem & Process Improvement Plan

  · 事后总结, 并提出过程改进计划

 1h

 

合计

 25h

posted @ 2017-04-08 10:19  小小d程序猿  阅读(583)  评论(0编辑  收藏  举报