代码改变世界

结对开发之四则运算(网页版)

2017-04-07 19:50  ovols  阅读(300)  评论(0编辑  收藏  举报

小组成员:     信1505-1班    20153274     罗振宇

                   信1505-1班    20153293     康学涛

任务要求:实现自动生成算术题,并且能够检查结果和将结果存放到数据库中的四则运算,并制作成网页版

程序设计思想:写好java程序后,需要将程序嵌入网页中,编写jsp脚本文件,使用数组来实现java和jsp的交互;session标签,可以实现网页之间参数的传递。

 

程序源代码:

1.界面设计:   

  Choose.jsp

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <title>选择界面</title>
 8 <style type="text/css">
 9 .aa {
10     font-weight: bold;
11 }
12 body {
13     background-color: #0CF;
14     background-image: url(b6.jpg);
15 }
16 </style>
17 </head>
18 <body>
19 <div style="text-align: center; font-family: 微软雅黑; font-size: 50px; color: #D2691E; "><strong><em>四则运算生成器</em></strong></div>
20 <div style="text-align: center; font-family: 微软雅黑; font-size: 15px; color: #FF0000; "><strong><em>Welcome To User The System</em></strong></div>
21 <br/>
22 <div style="text-align: center; font-family: 微软雅黑; font-size: 20px;"><em>请选择出题的范围</em></div><br />
23 <form  name="form1" method="post" action="Judge.jsp">
24 A:整数的四则计算<br />
25 B:真分数的四则计算<br />
26 C:有余数的运算<br />
27 <div style="text-align: center">
28 <font size=4>请选择:</font><input name="Choose" type="text"/>
29 <input name="" type="submit" value="提交"  />
30 <input name="" type="reset" value="重置" />
31 </div>
32 </form>
33 </body>
34 </html>

 

 2.

chuandi.jsp             通过session标签实现参数在网页之间的传递

<%@ 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>
<style type="text/css">
.aa {
    font-weight: bold;
}
body {
    background-color: #0CF;
    background-image: url(b6.jpg);
}
</style>
</head>
<body>
<div style="text-align: center; font-family: 微软雅黑; font-size: 50px; color: #D2691E; "><strong><em>四则运算生成器</em></strong></div>
<div style="text-align: center; font-family: 微软雅黑; font-size: 15px; color: #FF0000; "><strong><em>Welcome To User The System</em></strong></div>
<br/>
<div style="text-align: center; font-family: 微软雅黑; font-size: 20px;"><em>请选择出题的范围</em></div><br />
<form  name="form1" method="post" action="Judge.jsp">
A:整数的四则计算<br />
B:真分数的四则计算<br />
C:有余数的运算<br />
<div style="text-align: center">
<font size=4>请选择:</font><input name="Choose" type="text"/>
<input name="" type="submit" value="提交"  />
<input name="" type="reset" value="重置" />
</div>
</form>
</body>
</html>

 

 3.fenshu.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import = "java.util.Random"%>
<!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>Insert title here</title>
</head>
<body>
<%!
class calculate2
{
    public int m,n,x,y,c;//定义4个变量,还有一个符号变量
    public Random random=new Random();
    String s;//生成的计算式储存咋m里面
    int fanwei;
    public void shengcheng(int fanwei1)
    {
        fanwei=fanwei1;
        c=random.nextInt(4);
        x=random.nextInt(fanwei);
        y=random.nextInt(fanwei);
        m=random.nextInt(fanwei);
        n=random.nextInt(fanwei);//生成4个随机数在50以内,赋给x,y,m,n
        String fuhao;
        for(int i=0;;i++)
        {
            if(x==0)//不能生成0
            {
            x=random.nextInt(fanwei);
            }
            else
            {
                break;
            }
        }
        for(int i=0;;i++)
        {
            if(y==0||y==x)//不能生成0
            {
            y=random.nextInt(fanwei);
            }
            else
            {
                break;
            }
        }
        for(int i=0;;i++)
        {
            if(m==0)//不能生成0
            {
            m=random.nextInt(fanwei);
            }
            else
            {
                break;
            }
        }
        for(int i=0;;i++)
        {
            if(n==0||m==n)//不能生成0
            {
            n=random.nextInt(fanwei);
            }
            else
            {
                break;
            }
        }
        if(c==0)//通整数一样,0是加法,1减法,2乘法,3除法
         {
             fuhao="+";
         }
         else if(c==1)
         {
             fuhao="-";
         }
         else if(c==2)
         {
             fuhao="*";
         }
         else
         {
             fuhao="/";
         }
        int gongyue=Gongyue(x,y);
        x=x/gongyue;
        y=y/gongyue;
        gongyue=Gongyue(m,n);
        m=m/gongyue;
        n=n/gongyue;
    }
    public String shuchu()//定义输出函数
    {
        if(c==0)
        {
            if(x>y&&m>n)//生成的分母必须大于分子,输出不同的结果
            {
            s=y+"/"+x+"  +  "+n+"/"+m+"=";
            return jisuan(x,y,m,n,c);//返回计算结果
            }
            else if(x>y&&m<n)//生成的分母必须大于分子,输出不同的结果
            {
                s=y+"/"+x+"  +  "+m+"/"+n+"=";
                return jisuan(x,y,n,m,c);//返回计算结果
            }
            else if(x<y&&m>n)//生成的分母必须大于分子,输出不同的结果
            {
                s=x+"/"+y+"  +  "+n+"/"+m+"=";
                return jisuan(y,x,m,n,c);//返回计算结果
            }
            else//生成的分母必须大于分子,输出不同的结果
            {
                s=x+"/"+y+"  +  "+m+"/"+n+"=";
                return jisuan(y,x,n,m,c);//返回计算结果
            }
        }
        else if(c==1)
        {
            double x1=Double.parseDouble(String.valueOf(x));
            double y1=Double.parseDouble(String.valueOf(y));
            double m1=Double.parseDouble(String.valueOf(m));
            double n1=Double.parseDouble(String.valueOf(n));    
            if(x>y&&m>n)//生成的分母必须大于分子,输出不同的结果
            {    
                if((y1/x1)>(n1/m1))
                {
                    s=y+"/"+x+"  -  "+n+"/"+m+"=";
                    return jisuan(x,y,m,n,c);//返回计算结果
                }
                else
                {
                    s=n+"/"+m+"  -  "+y+"/"+x+"=";
                    return jisuan(m,n,x,y,c);//返回计算结果
                }
            }
            else if(x>y&&m<n)//生成的分母必须大于分子,输出不同的结果
            {
                if((y1/x1)>(m1/n1))//减数必须大于被减数
                {
                    s=y+"/"+x+"  -  "+m+"/"+n+"=";
                    return jisuan(x,y,n,m,c);//返回计算结果
                }
                else//减数必须大于被减数
                {
                    s=m+"/"+n+"  -  "+y+"/"+x+"=";
                    return jisuan(n,m,x,y,c);//返回计算结果
                }
            }
            else if(x<y&&m>n)//生成的分母必须大于分子,输出不同的结果
            {
                if((x1/y1)>(n1/m1))//减数必须大于被减数
                {
                    s=x+"/"+y+"  -  "+n+"/"+m+"=";
                    return jisuan(y,x,m,n,c);
                }
                else//减数必须大于被减数
                {
                    s=n+"/"+m+"  -  "+x+"/"+y+"=";
                    return jisuan(m,n,y,x,c);//返回计算结果
                }
            }
            else
            {
                if((x1/y1)>(m1/n1))//生成的分母必须大于分子,输出不同的结果//减数必须大于被减数
                {
                    s=x+"/"+y+"  -  "+m+"/"+n+"=";
                    return jisuan(y,x,n,m,c);//返回计算结果
                }
                else//减数必须大于被减数
                {
                    s=m+"/"+n+"  -  "+x+"/"+y+"=";
                    return jisuan(n,m,y,x,c);//返回计算结果
                }
            }
        }
        else if(c==2)
        {
            if(x>y&&m>n)//生成的分母必须大于分子,输出不同的结果
            {
            s=y+"/"+x+"  *  "+n+"/"+m+"=";
            return jisuan(x,y,m,n,c);//返回计算结果
            }
            else if(x>y&&m<n)//生成的分母必须大于分子,输出不同的结果
            {
                s=y+"/"+x+"  *  "+m+"/"+n+"=";
                return jisuan(x,y,n,m,c);//返回计算结果
            }
            else if(x<y&&m>n)//生成的分母必须大于分子,输出不同的结果
            {
                s=x+"/"+y+"  *  "+n+"/"+m+"=";
                return jisuan(y,x,m,n,c);
            }
            else//生成的分母必须大于分子,输出不同的结果
            {
                s=x+"/"+y+"  *  "+m+"/"+n+"=";
                return jisuan(y,x,n,m,c);//返回计算结果
            }
        }
        else
        {
            if(x>y&&m>n)//生成的分母必须大于分子,输出不同的结果
            {
            s=y+"/"+x+"  /  "+n+"/"+m+"=";
            return jisuan(x,y,m,n,c);//返回计算结果
            }
            else if(x>y&&m<n)//生成的分母必须大于分子,输出不同的结果
            {
                s=y+"/"+x+"  /  "+m+"/"+n+"=";
                return jisuan(x,y,n,m,c);//返回计算结果
            }
            else if(x<y&&m>n)//生成的分母必须大于分子,输出不同的结果
            {
                s=x+"/"+y+"  /  "+n+"/"+m+"=";
                return jisuan(y,x,m,n,c);//返回计算结果
            }
            else//生成的分母必须大于分子,输出不同的结果
            {
                s=x+"/"+y+"  /  "+m+"/"+n+"=";
                return jisuan(y,x,n,m,c);//返回计算结果
            }
        }
    }
    public String jisuan(int a,int b,int c,int d,int m)//计算结果的函数
    {
        String daan;
        int gongyue,gongbei;
        if(m==0)//加法计算的结果算法
        {
            gongbei=Gongbei(a,c);//求两个分母的最小公倍数
            int s1,s2,s3;
            s1=gongbei/a;
            s2=gongbei/c;
            s3=b*s1+d*s2;
            if(s3==gongbei)
            {
                return("1");
            }
            else
            {
                gongyue=Gongyue(s3,gongbei);
                int fenzi=s3/gongyue,fenmu=gongbei/gongyue;
                if(fenzi<fenmu)
                {
                    daan=String.valueOf(fenzi)+"/"+String.valueOf(fenmu);//通分
                    return daan;
                }
                else
                {
                    int zhi=fenzi/fenmu;
                    daan=String.valueOf(zhi)+"‘"+String.valueOf(fenzi-fenmu*zhi)+"/"+String.valueOf(fenmu);//通分
                    return daan;
                }
            }
        }
        else if(m==1)//减法计算的结果算法
        {
            gongbei=Gongbei(a,c);
            int s1,s2,s3;
            s1=gongbei/a;
            s2=gongbei/c;
            s3=b*s1-d*s2;
            if(s3==gongbei)
            {
                return("1");
            }
            else
            {
                if(s3==0)
                {
                    daan=String.valueOf("0");
                    return daan;
                }
                else
                {
                gongyue=Gongyue(s3,gongbei);
                int fenzi=s3/gongyue,fenmu=gongbei/gongyue;
                if(fenzi<fenmu)
                {
                    daan=String.valueOf(fenzi)+"/"+String.valueOf(fenmu);//通分
                    return daan;
                }
                else
                {
                    int zhi=fenzi/fenmu;
                    daan=String.valueOf(zhi)+"‘"+String.valueOf(fenzi-fenmu*zhi)+"/"+String.valueOf(fenmu);//通分
                    return daan;
                }
                }
            }
        }
        else if(m==2)//乘法计算的结果算法
        {
            int s1,s2;
            s1=a*c;
            s2=b*d;
            if(s1==s2)
            {
                return("1");
            }
            else
            {
                gongyue=Gongyue(s1,s2);
                int fenzi=s2/gongyue,fenmu=s1/gongyue;
                if(fenzi<fenmu)
                {
                    daan=String.valueOf(fenzi)+"/"+String.valueOf(fenmu);//通分
                    return daan;
                }
                else
                {
                    int zhi=fenzi/fenmu;
                    daan=String.valueOf(zhi)+"‘"+String.valueOf(fenzi-fenmu*zhi)+"/"+String.valueOf(fenmu);//通分
                    return daan;
                }
            }
        }
        else//除法计算的结果算法
        {
            int s1,s2;
            s1=a*d;
            s2=b*c;
            if(s1==s2)
            {
                return("1");
            }
            else
            {
                gongyue=Gongyue(s1,s2);
                int fenzi=s2/gongyue,fenmu=s1/gongyue;
                if(fenzi<fenmu)
                {
                    daan=String.valueOf(fenzi)+"/"+String.valueOf(fenmu);//通分
                    return daan;
                }
                else
                {
                    int zhi=fenzi/fenmu;
                    daan=String.valueOf(zhi)+"‘"+String.valueOf(fenzi-fenmu*zhi)+"/"+String.valueOf(fenmu);//通分
                    return daan;
                }
            }
        }
    }
    public int Gongbei(int a,int c)//求最小公倍数的函数
    {
        int gongbei;
        if(a>c)
        {
            gongbei=a;//公倍数从大的开始
            while(gongbei<=a*c)
            {
                if(gongbei%a==0&&gongbei%c==0)
                {
                    break;
                }
                gongbei++;
            }
        }
        else
        {
            gongbei=c;//公倍数从大的开始
            while(gongbei<=a*c)
            {
                if(gongbei%a==0&&gongbei%c==0)
                {
                    break;
                }
                gongbei++;
            }
        }
        return gongbei;
    }
    public int Gongyue(int gongbei,int s3)//求最大公约数的函数
    {
        int i=1,gongyue=0;
        if(gongbei>s3)//公约数从1到最小的数
        {
            while(i<=s3)
            {
                if(gongbei%i==0&&s3%i==0)
                {
                    gongyue=i;
                }
                i++;
            }
            return gongyue;
        }
        else
        {
            while(i<=gongbei)
            {
                if(gongbei%i==0&&s3%i==0)
                {
                    gongyue=i;
                }
                i++;
            }
            return gongyue;
        }
    }
    public int jianyan(String a[],int l)//检验是否生成重复计算式的函数
    {
         int flag=1;
           for(int i=0;i<l;i++)
           {
               if(s.equals(a[i]))
               {
                  flag=0;
                  break;
               }
           }
           return flag;
    }
}
int tishu;
int fanwei;
int m=0;
String shuju[]=new String[10000]; 
int flag=0;
calculate2 a=new calculate2();
String daan,daan1;
%>
<%
tishu=Integer.parseInt((String.valueOf(session.getAttribute("tishu"))));
fanwei=Integer.parseInt((String.valueOf(session.getAttribute("fanwei"))));
session.setAttribute("tishu", tishu);
if(m<tishu)
{
    a.shengcheng(fanwei);
    String f=a.shuchu();
    shuju[m]=a.s;
    flag=a.jianyan(shuju, m);//返回是否有重复
    if(flag==1)//如果没有就是1
    {
    if(m+1==tishu)
    {daan=a.shuchu();
    session.setAttribute("shuju", shuju[m]);
    session.setAttribute("daan", daan);
    session.setAttribute("m", m);
        %>
    <form id="form2" name="form2" method="post" action="fenshuhuoqu.jsp">
    <div style="text-align:center">
    <%out.print(m+1+"."+shuju[m]+"=");
    m=0;%>
    <br>
    <br>
    <br>
    <br>
    <br>
    请输入答案:<input name="daan1" type="text" value=""/><br /><br/>
    <input name="" type="submit" value="提交" />
    </div>
    </form>
        <%
    }
    else
    {
        daan=a.shuchu();
        session.setAttribute("shuju", shuju[m]);
        session.setAttribute("daan", daan);
        session.setAttribute("m", m);
        %>
    <form id="form2" name="form2" method="post" action="fenchuandi.jsp">
    <div style="text-align:center">
    <%out.print(m+1+"."+shuju[m]+"=");%>
    <br>
    <br>
    <br>
    <br>
    <br>
    请输入答案:<input name="daan1" type="text" value=""/><br /><br/>
    <input name="" type="submit" value="下一个" />
    </div>
    </form>
        <%
        m++;
        flag=0;
    }
    
    }
    else
    {
        response.setHeader("refresh","0;url = fenshu.jsp");
    }
}
%>
</body>
</html>

 

 

3.2  yushu.jsp 

  1 <%@ page language="java" contentType="text/html; charset=UTF-8"
  2     pageEncoding="UTF-8" import="java.util.Random" import="java.sql.Connection" import="java.sql.DriverManager"%>
  3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  4 <html>
  5 <head>
  6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  7 <title>Insert title here</title>
  8 </head>
  9 <body>
 10 <%!
 11 class calculate3
 12 {
 13     public int a,b,d;
 14     public Random random=new Random();
 15     String m;
 16     int fanwei;
 17     public String shengcheng(int fanwei1)
 18     {
 19         fanwei = fanwei1;
 20         a = random.nextInt(fanwei);
 21         b = random.nextInt(fanwei);
 22         String fuhao;
 23         fuhao = "/";
 24         m = String.valueOf(a) + fuhao + String.valueOf(b);
 25         return m ;
 26     }
 27     public String shuchu()
 28     {
 29         String s;
 30         int c , c1;
 31         if(a >= b)
 32         {
 33             c = a % b;
 34             c1 = (a - c) / b;
 35             
 36         }
 37         else
 38         {
 39             c = b % a;
 40             c1 = (b - c) / a;
 41         }
 42         s = String.valueOf(c1) + "余" + String.valueOf(c);
 43         return s;
 44     }
 45     public int jianyan(String a[],int s)//检验是否有重复的式子,如果有返回0,没有就返回1
 46     {
 47        int flag = 1;
 48        for(int i = 0;i < s;i ++)
 49        {
 50            if(m.equals( a[i]) )//数组a里面是生成的式子
 51            {
 52               flag = 0;
 53               break;
 54            }
 55        }
 56        return flag;
 57     }    
 58 }
 59 int tishu;
 60 int fanwei;
 61 int m = 0;
 62 String shuju[] = new String[10000]; 
 63 int flag=0;
 64 calculate3 a=new calculate3();
 65 String daan,daan1;
 66 String zhengque = "",cuowu = "";
 67 %>
 68 <%
 69 tishu=Integer.parseInt((String.valueOf(session.getAttribute("tishu"))));
 70 fanwei=Integer.parseInt((String.valueOf(session.getAttribute("fanwei"))));
 71 session.setAttribute("tishu", tishu);
 72 if(m < tishu)
 73 {
 74     shuju[m] = a.shengcheng(fanwei);
 75     flag = a.jianyan(shuju, m);
 76     if(flag == 1)
 77     {
 78     if(m+1 == tishu)
 79     {daan=a.shuchu();
 80     session.setAttribute("shuju", shuju[m]);
 81     session.setAttribute("daan", daan);
 82     session.setAttribute("m", m);
 83         %>
 84     <form id = "form2" name = "form2" method = "post" action = "yushuhuoqu.jsp">
 85     <div style="text-align:center">
 86     <%out.print(m+1+"."+shuju[m]+"=");
 87     m=0;%>
 88     <br>
 89     <br>
 90     <br>
 91     <br>
 92     <br>
 93     请输入商:<input name="daan1" type="text" value=""/><br /><br/>
 94     请输入余数:<input name="daan2" type="text" value=""/><br>
 95     <br>
 96     <input name="" type="submit" value="提交" />
 97     </div>
 98     </form>
 99         <%
100     }
101     else
102     {
103         daan=a.shuchu();
104         session.setAttribute("shuju", shuju[m]);
105         session.setAttribute("daan", daan);
106         session.setAttribute("m", m);
107         %>
108     <form id="form2" name="form2" method="post" action="yushuhuoqu.jsp">
109     <div style="text-align:center">
110     <%out.print(m+1+"."+shuju[m]+"=");%>
111     <br>
112     <br>
113     <br>
114     <br>
115     <br>
116     请输入答案:<input name="daan1" type="text" value=""/><br /><br/>
117     <input name="" type="submit" value="下一个" />
118     </div>
119     </form>
120         <%
121         m++;
122         flag=0;
123     }
124     
125     }
126     else
127     {
128         response.setHeader("refresh","1;url = yushu.jsp");
129     }
130 }
131 %>
132 </body>
133 </html>

 

judge.jsp

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <title>Insert title here</title>
 8 <style type="text/css">
 9 .aa {
10     font-weight: bold;
11 }
12 body {
13     background-color: #0CF;
14     background-image: url(d.jpg);
15 }
16 </style>
17 </head>
18 <body>
19 <%
20  String panduan=request.getParameter("Choose");
21 if(panduan.equals("A"))
22 {
23     %>
24     <form id="form2" name="form2" method="post" action="chuandi.jsp">
25     <div style="text-align:center">
26     请输入出题的个数:<input name="geshu" type="text" value=""/><br /><br/>
27     请选择出题的范围:<input name="fanwei" type="text" value=""/><br/><br/>
28     <input name="" type="submit" value="提交" />
29     </div>
30     </form>
31     <%
32 }
33 else if(panduan.equals("B"))
34 {
35     %>
36     <form id="form3" name="form4" method="post" action="fenchuandi.jsp">
37     <div style="text-align:center">
38     请输入出题的个数:<input name="geshu" type="text" value=""/><br /><br/>
39     请选择出题的范围:<input name="fanwei" type="text" value=""/><br/><br/>
40     <input name="" type="submit" value="提交" />
41     </div>
42     </form>
43     <%
44 }
45 else if(panduan.equals("C"))
46 {
47     %>
48     <form id="form2" name="form2" method="post" action="yushu.jsp">
49     <div style="text-align:center">
50     请输入出题的个数:<input name="geshu" type="text" value=""/><br /><br/>
51     请选择出题的范围:<input name="fanwei" type="text" value=""/><br/><br/>
52     <input name="" type="submit" value="提交" />
53     </div>
54     </form>
55     <%
56 }
57 
58 else
59 {
60     %>
61     <script type="text/javascript">
62     alert("输入错误,请点击确定重新输入!!!");
63     </script>
64     <% 
65     response.setHeader("refresh","0;url = Choose.html");
66 }
67     %>
68 </body>
69 </html>

 

zhengshu.jsp

  1 <%@ page language="java" contentType="text/html; charset=UTF-8"
  2     pageEncoding="UTF-8" import="java.util.Random" import="java.sql.Connection" import="java.sql.DriverManager"%>
  3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  4 <html>
  5 <head>
  6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  7 <title>Insert title here</title>
  8 </head>
  9 <body>
 10 <%!
 11 class Suan1//生成整数计算的类
 12 {
 13     public int x,y,c;
 14     public Random random=new Random();
 15     String m;
 16     int fanwei;
 17     public String shengcheng(int fanwei1)//自动生成数的函数
 18     {
 19          fanwei=fanwei1;
 20          c=random.nextInt(4);
 21          String fuhao;
 22          x=random.nextInt(fanwei);
 23          y=random.nextInt(fanwei);
 24          if(c==0)
 25          {
 26              fuhao="+";
 27              m=String.valueOf(x)+fuhao+String.valueOf(y);
 28              
 29          }
 30          else if(c==1)
 31          {
 32              fuhao="-";
 33              if(x>=y)
 34              {
 35                  m=String.valueOf(x)+fuhao+String.valueOf(y);
 36              }
 37              else
 38              {
 39                  m=String.valueOf(y)+fuhao+String.valueOf(x);
 40              }
 41          }
 42          else if(c==2)
 43          {
 44              fuhao="*";
 45              m=String.valueOf(x)+fuhao+String.valueOf(y);
 46          }
 47          else
 48          {
 49              fuhao="/";
 50              for(int i=0;;i++)
 51              {
 52                  if(y==0)
 53                  {
 54                      y=random.nextInt(fanwei);
 55                  }
 56                  else
 57                  {
 58                      break;
 59                  }
 60              }
 61              m=String.valueOf(x)+fuhao+String.valueOf(y);
 62          }
 63          return m;
 64          
 65     }
 66     public String shuchu()//定义输出函数
 67     {
 68         if(c==0)
 69         {
 70             return (String.valueOf(x+y));//并且返回计算的结果
 71         }
 72         else if(c==1)
 73         {
 74             if(x>=y)//将较大的数放在前面,不能出现负数
 75             {
 76             return (String.valueOf(x-y));
 77             }
 78             else
 79             {
 80             return (String.valueOf(y-x));
 81             }
 82         }
 83         else if(c==2)
 84         {
 85             return (String.valueOf(x*y));
 86         }
 87         else
 88         {
 89             if(x%y==0)
 90             {
 91                 return (String.valueOf(x/y));
 92             }
 93             else
 94             {
 95                 if(x>y)
 96                 {
 97                 int shang=x/y;
 98                 int yushu=x-y*shang;
 99                 return (String.valueOf(shang)+"‘"+String.valueOf(yushu)+"/"+String.valueOf(y));
100                 }
101                 else
102                 {
103                 return (String.valueOf(x)+"/"+String.valueOf(y));
104                 }
105             }
106         }
107     }
108     public int fanhuic()
109     {
110         return c;
111     }
112     public int jianyan(String a[],int s)//检验是否有重复的式子,如果有返回0,没有就返回1
113     {
114        int flag=1;
115        for(int i=0;i<s;i++)
116        {
117            if(m.equals(a[i]))//数组a里面是生成的式子
118            {
119               flag=0;
120               break;
121            }
122        }
123        return flag;
124     }
125 }
126 int tishu;
127 int fanwei;
128 int m=0;
129 String shuju[]=new String[10000]; 
130 int flag=0;
131 Suan1 a=new Suan1();
132 String daan,daan1;
133 String zhengque="",cuowu="";
134 %>
135 <%
136 tishu=Integer.parseInt((String.valueOf(session.getAttribute("tishu"))));
137 fanwei=Integer.parseInt((String.valueOf(session.getAttribute("fanwei"))));
138 session.setAttribute("tishu", tishu);
139 if(m<tishu)//生成30个计算式
140 {
141     shuju[m]=a.shengcheng(fanwei);//将生成的计算式储存咋数组里面
142     flag=a.jianyan(shuju, m);//返回是否有重复
143     if(flag==1)//如果没有就是1
144     {
145     if(m+1==tishu)
146     {daan=a.shuchu();
147     session.setAttribute("shuju", shuju[m]);
148     session.setAttribute("daan", daan);
149     session.setAttribute("m", m);
150         %>
151     <form id="form2" name="form2" method="post" action="huoqu.jsp">
152     <div style="text-align:center">
153     <%out.print(m+1+"."+shuju[m]+"=");
154     m=0;%>
155     <br>
156     <br>
157     <br>
158     <br>
159     <br>
160     请输入答案:<input name="daan1" type="text" value=""/><br /><br/>
161     <input name="" type="submit" value="提交" />
162     </div>
163     </form>
164         <%
165     }
166     else
167     {
168         daan=a.shuchu();
169         session.setAttribute("shuju", shuju[m]);
170         session.setAttribute("daan", daan);
171         session.setAttribute("m", m);
172         %>
173     <form id="form2" name="form2" method="post" action="huoqu.jsp">
174     <div style="text-align:center">
175     <%out.print(m+1+"."+shuju[m]+"=");%>
176     <br>
177     <br>
178     <br>
179     <br>
180     <br>
181     请输入答案:<input name="daan1" type="text" value=""/><br /><br/>
182     <input name="" type="submit" value="下一个" />
183     </div>
184     </form>
185         <%
186         m++;
187         flag=0;
188     }
189     
190     }
191     else
192     {
193         response.setHeader("refresh","1;url = zhengshu.jsp");
194     }
195 }
196 %>
197 
198 
199 </body>
200 </html>

 

4.获取

yushuhuoqu.jsp

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8" import="java.sql.Connection" import="java.sql.DriverManager"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <title>Insert title here</title>
 8 </head>
 9 <body>
10 <%!
11 int tishu1;
12 String error="",zhengque=""; 
13 %>
14 <%
15 try
16 {
17 Connection con = null; //定义一个MYSQL链接对象
18 Class.forName("com.mysql.jdbc.Driver").newInstance(); //MYSQL驱动
19 con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "970803"); //链接本地MYSQL
20 java.sql.Statement stmt; //创建声明
21 stmt = con.createStatement();
22 String shuju=String.valueOf(session.getAttribute("shuju"));
23 String daan=String.valueOf(session.getAttribute("daan"));
24 int weizhi = daan.indexOf("余");
25 String shang1 = daan.substring(0,weizhi);
26 String yushu1 = daan.substring(weizhi + 1);
27 int m=Integer.parseInt(String.valueOf(session.getAttribute("m")));
28 tishu1=Integer.parseInt((String.valueOf(session.getAttribute("tishu"))));
29 String shang = request.getParameter("daan1");
30 String yushu = request.getParameter("daan2");
31 String sql="INSERT INTO 余数运算 (problem,shang,yushu,usershang,useryushu) VALUES ('"+shuju+" = "+"','"+shang1+"','"+yushu1+"','"+shang+"','"+ yushu+"')";
32 stmt.executeUpdate(sql);
33 if(daan.equals(shang + "余" + yushu))
34 {
35     zhengque=zhengque+String.valueOf(m+1)+",";
36 }
37 else
38 {
39     error=error+String.valueOf(m+1)+",";
40 }
41 if(m+1==tishu1)
42 {
43     sql="INSERT INTO Grade (zhengque,cuowu) VALUES ('"+zhengque+"','"+error+"')";
44     stmt.executeUpdate(sql);             
45     
46     %>
47     <form id="form2" name="form2" method="post" action="Choose.jsp">
48        <div style="text-align:center">
49        <% out.print("正确的题目是:"+zhengque+"错误的题目是:"+error+"点击确定返回主界面"); 
50         zhengque="";
51     error="";  %>
52        <input name="" type="submit" value="提交" />
53        </div>
54        </form>
55        <%
56 }
57 else
58 {
59 response.setHeader("refresh","0;url = yushu.jsp");
60 }
61 }
62 catch (Exception e) 
63 {
64     System.out.print("MYSQL ERROR:" + e.getMessage());
65 } 
66 %>
67 </body>
68 </html>

 

fenshuhuoqu

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8" import="java.sql.Connection" import="java.sql.DriverManager"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <title>Insert title here</title>
 8 </head>
 9 <body>
10 <%!
11 int tishu1;
12 String error="",zhengque=""; 
13 %>
14 <%
15 try
16 {
17 Connection con = null; //定义一个MYSQL链接对象
18 Class.forName("com.mysql.jdbc.Driver").newInstance(); //MYSQL驱动
19 con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "970803"); //链接本地MYSQL
20 java.sql.Statement stmt; //创建声明
21 stmt = con.createStatement();
22 String shuju=String.valueOf(session.getAttribute("shuju"));
23 String daan=String.valueOf(session.getAttribute("daan"));
24 int m=Integer.parseInt(String.valueOf(session.getAttribute("m")));
25 tishu1=Integer.parseInt((String.valueOf(session.getAttribute("tishu"))));
26 String daan1=request.getParameter("daan1");
27 String sql="INSERT INTO 真分数的四则运算 (problem,answer,useranswer) VALUES ('"+shuju+" = "+"','"+daan+"','"+daan1+"')";
28 stmt.executeUpdate(sql);
29 if(daan.equals(daan1))
30 {
31     zhengque=zhengque+String.valueOf(m+1)+",";
32 }
33 else
34 {
35     error=error+String.valueOf(m+1)+",";
36 }
37 if(m+1==tishu1)
38 {
39     sql="INSERT INTO Grade (zhengque,cuowu) VALUES ('"+zhengque+"','"+error+"')";
40     stmt.executeUpdate(sql);             
41     
42     %>
43     <form id="form2" name="form2" method="post" action="Choose.jsp">
44        <div style="text-align:center">
45        <% out.print("正确的题目是:"+zhengque+"错误的题目是:"+error+"点击确定返回主界面");
46         zhengque="";
47     error="";  %>
48        <input name="" type="submit" value="提交" />
49        </div>
50        </form>
51        <%
52 }
53 else
54 {
55 response.setHeader("refresh","0;url = fenshu.jsp");
56 }
57 }
58 catch (Exception e) 
59 {
60     System.out.print("MYSQL ERROR:" + e.getMessage());
61 } 
62 %>
63 </body>
64 </html>

 

huoqu

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8" import="java.sql.Connection" import="java.sql.DriverManager"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <title>Insert title here</title>
 8 </head>
 9 <body>
10 <%!
11 int tishu1;
12 String error="",zhengque=""; 
13 %>
14 <%
15 try
16 {
17 Connection con = null; //定义一个MYSQL链接对象
18 Class.forName("com.mysql.jdbc.Driver").newInstance(); //MYSQL驱动
19 con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "970803"); //链接本地MYSQL
20 java.sql.Statement stmt; //创建声明
21 stmt = con.createStatement();
22 String shuju=String.valueOf(session.getAttribute("shuju"));
23 String daan=String.valueOf(session.getAttribute("daan"));
24 int m=Integer.parseInt(String.valueOf(session.getAttribute("m")));
25 tishu1=Integer.parseInt((String.valueOf(session.getAttribute("tishu"))));
26 String daan1=request.getParameter("daan1");
27 String sql="INSERT INTO 正数运算 (problem,answer,useranswer) VALUES ('"+shuju+" = "+"','"+daan+"','"+daan1+"')";
28 stmt.executeUpdate(sql);
29 if(daan.equals(daan1))
30 {
31     zhengque=zhengque+String.valueOf(m+1)+",";
32 }
33 else
34 {
35     error=error+String.valueOf(m+1)+",";
36 }
37 if(m+1==tishu1)
38 {
39     sql="INSERT INTO Grade (zhengque,cuowu) VALUES ('"+zhengque+"','"+error+"')";
40     stmt.executeUpdate(sql);             
41     
42     %>
43     <form id="form2" name="form2" method="post" action="Choose.jsp">
44        <div style="text-align:center">
45        <% out.print("正确的题目是:"+zhengque+"错误的题目是:"+error+"点击确定返回主界面"); 
46         zhengque="";
47     error="";  %>
48        <input name="" type="submit" value="提交" />
49        </div>
50        </form>
51        <%
52 }
53 else
54 {
55 response.setHeader("refresh","0;url = zhengshu.jsp");
56 }
57 }
58 catch (Exception e) 
59 {
60     System.out.print("MYSQL ERROR:" + e.getMessage());
61 } 
62 %>
63 </body>
64 </html>

 

fenerror

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <title>Insert title here</title>
 8 </head>
 9 <body>
10 <form id="form2" name="form2" method="post" action="fenchuandi.jsp">
11 <div style="text-align:center">
12 请输入出题的个数:<input name="geshu" type="text" value=""/><br /><br/>
13 请选择出题的范围:<input name="fanwei" type="text" value=""/><br/><br/>
14 <input name="" type="submit" value="提交" />
15 </div>
16 </form>
17 </body>
18 </html>

 

程序结果截图

实验总结:

         第一次进行合作磨合,交流不是很多,最后完成度挺满意的,还是有点不适应团队合作和分工,这次锻炼了自己许多,意识到了个人在团队中的作用,不能因为一个人的风格影响团队,要为大局考虑,一个团队应该是一荣俱荣。

 

 

 

实际PSP

PSP2.1

Personal Software Process Stages

Time

Planning

计划

  23h

  · Estimate

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

 

Development

开发

  18h

  · Analysis

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

  2h

  · Design Spec

  · 生成设计文档

  2h

  · Design Review

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

  1h

  · Coding Standard

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

 1h

  · Design

  · 具体设计

  1h

  · Coding

  · 具体编码

  6h

  · Code Review

  · 代码复审

  3h

  · Test

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

  2h

Reporting

报告

   5h

  · Test Report

  · 测试报告

   2h

  · Size Measurement

  · 计算工作量

   2h

  · Postmortem & Process Improvement Plan

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

   1h

 

合计