結對開發之四則運算(網頁版)

小組成員:     信1505-1班    20153274     羅振宇javascript

                   信1505-1班    20153293     康學濤css

任務要求:實現自動生成算術題,而且可以檢查結果和將結果存放到數據庫中的四則運算,並製做成網頁版html

程序設計思想:寫好java程序後,須要將程序嵌入網頁中,編寫jsp腳本文件,使用數組來實現java和jsp的交互;session標籤,能夠實現網頁之間參數的傳遞。java

 

程序源代碼:mysql

1.界面設計:   算法

  Choose.jspsql

 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.jspsession

<%@ 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

 

合計

相關文章
相關標籤/搜索