软件工程结对作业01

  

web版本四则运算

复制代码
 //Szys.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 </head> 9 <script> 10 function myFunction() 11 { 12 var x=document.getElementById("demo").value; 13 if(x==""||isNaN(x)) 14 { 15 alert("限制条件输入错误,请重新输入"); 16 } 17 } 18 </script> 19 <body> 20 <form mehod="post" action="ct.jsp"> 21 <center> 22 请输入出题数目:<input id="demo" type="test" name="numbers"><br><br> 23 请输入出题的运算元数最大值:<input id="demo" type="test" name="yuanshu"><br><br> 24 请输入出题中最大数字:<input id="demo" type="test" name="fanwei"><br><hr> 25 是否含有乘除法:<input type="radio" name="chengchu" value=1>是 26 <input type="radio" name="chengchu" value=0>否<br><br> 27 是否含有括号:<input type="radio" name="kuohao" value=1>是 28 <input type="radio" name="kuohao" value=0>否<br><br> 29 是否包含假分数:<input type="radio" name="jiafenshu" value=1>是 30 <input type="radio" name="jiafenshu" value=0>否<br><hr> 31 <input type="submit" onclick="myFunction()" value="出题"> 32 <input type="reset" value="重置"> 33 </center> 34 </form> 35 </body> 36 </html>
//ct.jsp
复制代码
  1 <%@ page language="java" contentType="text/html; charset=utf-8"
  2     pageEncoding="utf-8"%>
  3 <%@ page import="java.util.*"%>
  4 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  5 <html>
  6 <head>
  7 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  8 <title>请回答题目</title>
  9 </head>
 10 <body>
 11 <form action="judge.jsp" method="post">
 12 <%
 13     int numbers=Integer.parseInt(request.getParameter("numbers"));
 14     int yuanshu=Integer.parseInt(request.getParameter("yuanshu"));
 15     int fanwei=Integer.parseInt(request.getParameter("fanwei"));
 16     int chengchu=Integer.parseInt(request.getParameter("chengchu"));
 17     int kuohao=Integer.parseInt(request.getParameter("kuohao"));
 18     int jiafenshu=Integer.parseInt(request.getParameter("jiafenshu"));
 19     int i,n;
 20     int dzs;//定制题的数目;
 21     int js = 1;//题目序号计数;
 22     int szs ;//字符随机产生的个数
 23     int fhs;//符号产生的个数
 24     int[] re = new int[numbers];
 25     int[] result = new int[numbers];
 26     dzs=numbers;
 27     int number[]=new int[10000000];
 28     char fu[]=new char[10000000];
 29     char fu2[]=new char[10000000];
 30     char c[]={'+','-','*','/'};
 31     char d[]={'+','-'};
 32     //生成题目的随机数数组
 33     for(i=0;i<10000000;i++)
 34     {
 35         int x=(int)(Math.random()*fanwei);
 36         number[i]=x;
 37     }
 38     //生成随机符号的数组
 39     for(i=0;i<10000000;i++)
 40     {
 41         Random random=new Random();
 42         int index=random.nextInt(c.length);
 43         int index2=random.nextInt(c.length-2);
 44         char resultChar=c[index];
 45         char resultChar2=d[index2];
 46         fu[i]=resultChar;
 47         fu2[i]=resultChar2;
 48         
 49     }
 50     
 51     //输出题目
 52     if(chengchu==1&&jiafenshu==1&&kuohao==0)
 53     {
 54         for(n=0;n<dzs;n++)
 55         {
 56             Random random1=new Random();//随机运算数字数以及符号数
 57             szs = random1.nextInt(yuanshu)%(yuanshu-2+1)+2;
 58             fhs=szs-1;
 59             out.print(js+". ");
 60             for(i=0;i<szs-1;i++)
 61             {
 62                 Random random2=new Random();
 63                 int op=random2.nextInt(1000000);//数组内的随机调用所用的下表随机减少重复
 64                 out.print(number[op]);
 65                 out.print(fu[op]);
 66             }
 67             Random random2=new Random();
 68             int op=random2.nextInt(1000000);//数组内的随机调用所用的下表随机减少重复
 69             out.print(number[op]);
 70             out.print(" = "+"<br>");
 71             js++;
 72             %>
 73             <input type="text" name=<%=re[n]%>><br>
 74             <%
 75         }
 76     }
 77     if(chengchu==0&&jiafenshu==1&&kuohao==0)
 78     {
 79         for(n=0;n<dzs;n++)
 80         {
 81         Random random1=new Random();//随机运算数字数以及符号数
 82         szs = random1.nextInt(yuanshu)%(yuanshu-2+1)+2;
 83         fhs=szs-1;
 84         out.print(js+". ");
 85         for(i=0;i<szs-1;i++)
 86         {
 87             Random random2=new Random();
 88             int op=random2.nextInt(1000000);//数组内的随机调用所用的下表随机减少重复
 89             out.print(number[op]);
 90             out.print(fu2[op]);
 91         }
 92         Random random2=new Random();
 93         int op=random2.nextInt(1000000);//数组内的随机调用所用的下表随机减少重复
 94         out.print(number[op]);
 95         out.print(" = "+"<br>");
 96         js++;
 97         %>
 98         <input type="text" name=<%=re[n]%>><br>
 99         <%
100         }
101     }
102      if(chengchu==1&&jiafenshu==0&&kuohao==0)
103         {
104             for(n=0;n<dzs;n++)
105             {
106                 Random random1=new Random();//随机运算数字数以及符号数
107                 szs = random1.nextInt(yuanshu)%(yuanshu-2+1)+2;
108                 fhs=szs-1;
109                 out.print(js+". ");
110                 for(i=0;i<szs-1;i++)
111                 {
112                     Random random2=new Random();
113                     int op=random2.nextInt(1000000);//数组内的随机调用所用的下表随机减少重复
114                     out.print(number[op]);
115                     out.print(fu[op]);
116                 }
117                 Random random2=new Random();
118                 int op=random2.nextInt(1000000);//数组内的随机调用所用的下表随机减少重复
119                 out.print(number[op]);
120                 out.print(" = "+"<br>");
121                 js++;
122                 %>
123                 <input type="text" name=<%=re[n]%>><br>
124                 <%
125             }
126         }
127      if(chengchu==0&&jiafenshu==0&&kuohao==0)
128         {
129             for(n=0;n<dzs;n++)
130             {
131                 Random random1=new Random();//随机运算数字数以及符号数
132                 szs = random1.nextInt(yuanshu)%(yuanshu-2+1)+2;
133                 fhs=szs-1;
134                 out.print(js+". ");
135                 for(i=0;i<szs-1;i++)
136                 {
137                     Random random2=new Random();
138                     int op=random2.nextInt(1000000);//数组内的随机调用所用的下表随机减少重复
139                     out.print(number[op]);
140                     out.print(fu2[op]);
141                 }
142                 Random random2=new Random();
143                 int op=random2.nextInt(1000000);//数组内的随机调用所用的下表随机减少重复
144                 out.print(number[op]);
145                 out.print(" = "+"<br>");
146                 js++;
147                 %>
148                 <input type="text" name=<%=re[n]%>><br>
149                 <%
150             }
151         }
152     if(chengchu==1&&jiafenshu==1&&kuohao==1)
153     {
154         for(n=0;n<dzs;n++)
155         {
156         Random random1=new Random();//随机运算数字数以及符号数
157         szs = random1.nextInt(yuanshu)%(yuanshu-2+1)+2;
158         fhs=szs-1;
159         out.print(js+". ");
160         for(i=0;i<szs-1;i++)
161         {
162             Random random2=new Random();
163             int op=random2.nextInt(1000000);//数组内的随机调用所用的下表随机减少重复
164             out.print(number[op]);
165             if(szs>=3 && i==2)
166             {
167                 out.print(")");
168             }
169         
170             out.print(fu[op]);
171             if(szs>=3 && i==0)
172             {
173                 out.print("(");
174             }
175         
176         }
177         Random random2=new Random();
178         int op=random2.nextInt(1000000);//数组内的随机调用所用的下表随机减少重复
179         out.print(number[op]);
180         out.print(" = "+"<br>");
181         js++;
182         %>
183         <input type="text" name=<%=re[n]%>><br>
184         <%
185         }
186     }
187     session.setAttribute("huida", re);
188     session.setAttribute("daan",result);
189     session.setAttribute("timushu",numbers);
190 %>
191 <input type="submit" value="提交题目">
192 <input type="reset" value="清空所答的答案!">
193 </form>
194 </body>
195 </html>
复制代码

运行截图:

posted on 2017-04-07 17:08  zhijia  阅读(130)  评论(0编辑  收藏  举报

导航