首页 > 代码库 > 软件工程概论作业02

软件工程概论作业02

     这周,我们上了软件工程概论第三节课,终于体会到的程序员的不易,作业一次比一次难,老师提出的要求越来越多,就像未来的客户一样,要求永远无止境。

     这次还在上次的要求上提出了新的要求,要求可选择整数还是分数,可指定范围,不可重复。

     可怜的二柱子同学,老师又对他的自动出题系统提出了新的要求: 可以控制下列参数: 是否有乘除法; 是否有括号(最多可以支持十个数参与计算); 数值范围; 加减有无负数; 除法有无余数!

      

日期

开始时间

结束时间

中断时间

净时间

活动

备注

C

U

3/10

14:00

16:00

 

120

上课

软件工程概论B

 

 

 

16:20

17:00

 

40

 

把程序的思路写下来

 

 

3/12

15:00

18:00

 

180

编程

四则运算2

 

 

 

18:30

19:00

 

30

编程

四则运算2

 

 

3/12

20:00

21:00

 

60

写博客

四则运算2 的报告

 

 
  1 package demo;
  2 import java.*;
  3 import java.util.*;
  4 
  5 
  6 public class Main {
  7     public static void main(String args[])
  8     {
  9         Scanner scan;
 10         scan = new Scanner(System.in);
 11         int flag;//标志
 12         int max;//最大值范围
 13         int ysf;//运算符
 14         int num;//数量
 15         int i = 0;
 16         char[] ch = new char[4];
 17         ch[0] = ‘+‘;
 18         ch[1] = ‘-‘;
 19         ch[2] = ‘*‘;
 20         ch[3] = ‘/‘;
 21         String[] str = new String[200];
 22         str[0] = null;
 23         String s = null;
 24         System.out.println("请输入你需要的题目形式:1、整数类型  2、分数类型");
 25         flag = scan.nextInt();
 26         int a,b,a1,b1;
 27         double A,B,A1,B1;
 28         if(flag == 1)
 29         {
 30             System.out.println("请输入您希望的最大数值范围:");
 31             max = scan.nextInt();
 32             System.out.println("请输入题目的数量:");
 33             num = scan.nextInt();
 34             while(num > 0)
 35             {
 36                 a = (int)(Math.random()*max);
 37                 b = (int)(Math.random()*max) + 1;
 38                 ysf = (int)(Math.random()*4);
 39                 s = a + " " + ch[ysf] + " " + b + " =";
 40                 if(Check(str,s,i) != 1)
 41                 {
 42                     str[i] = s;
 43                     System.out.print(str[i]);
 44                     i ++;
 45                 }
 46                 if(ysf == 0)
 47                 {
 48                     System.out.println(intjia(a,b));
 49                 }
 50                 if(ysf == 1)
 51                 {
 52                     System.out.println(intjian(a,b));
 53                 }
 54                 if(ysf == 2)
 55                 {
 56                     System.out.println(intcheng(a,b));
 57                 }
 58                 if(ysf == 3)
 59                 {
 60                     System.out.println(intchu(a,b));
 61                 }
 62             }
 63         }
 64         int flagA = 0;
 65         int flagB = 0;
 66         if(flag == 2)
 67         {
 68             System.out.println("请输入题目的数量:");
 69             num = scan.nextInt();
 70             for(int j = 0;i < num;i ++)
 71             {
 72                 flagA = SuiJileixing();
 73                 flagB = SuiJileixing();        
 74                 if(flagA == 1 && flagB == 0)
 75                 {
 76                     a = SuiJi1();
 77                     b = SuiJi1();
 78                     b1 = SuiJi1() + 1;
 79                     if(b < b1)
 80                     {
 81                         b = b;
 82                     }
 83                     else 
 84                     {
 85                         b1 = b1 + b;
 86                     }
 87                     ysf = SuiJiyunsuanfu();
 88                     s = a + " " + ch[ysf] + " (" + b + "/" + b1 + ") = ";
 89                     if(Check(str,s,i) != 1)
 90                     {
 91                         str[i] = s;
 92                         System.out.print(str[i]);
 93                         A = (double)a;
 94                         B = (double)b;
 95                         B1 = (double)b1;
 96                         show(A,B/B1,ysf);
 97                         i ++;
 98                     }
 99                 }
100                 else if(flagA == 0 && flagB == 1)
101                 {
102                     a = SuiJi1();
103                     a1 = SuiJi1() + 1;
104                     b = SuiJi1();
105                     if(a > a1)
106                     {
107                         a1 = a + a1;
108                     }
109                     ysf = SuiJiyunsuanfu();
110                     s = "(" + a + "/" + a1 + ") " + ch[ysf] + " " + b + " = ";
111                     if(Check(str,s,i) != 1)
112                     {
113                         str[i] = s;
114                         System.out.print(str[i]);
115                         A = (double)a;
116                         A1 = (double)a1;
117                         B = (double)b;
118                         show(A/A1,B,ysf);
119                         i ++;
120                     }
121                 }
122                 else
123                 {
124                     a = SuiJi1();
125                     a1 = SuiJi1() + 1;
126                     b = SuiJi1();
127                     b1 = SuiJi1() + 1;
128                     if(a > a1)
129                     {
130                         a1 = a + a1;
131                     }
132                     if(b > b1)
133                     {
134                         b1 = b + b1;
135                     }
136                     ysf = SuiJiyunsuanfu();
137                     s =  "(" + a + "/" + a1 + ") " + ch[ysf] + " " + b + "/" + b1 + " = ";
138                     if(Check(str,s,i) != 1)
139                     {
140                         str[i] = s;
141                         System.out.print(str[i]);
142                         A = (double)a;
143                         A1 = (double)a1;
144                         B = (double)b;
145                         B1 = (double)b1;
146                         show(a/a1,b/b1,ysf);
147                         i ++;
148                     }
149                 }
150 
151                 
152                 
153             }
154             
155         
156         }
157         
158     }
159     public static int Check(String s[],String str,int ss)
160     {
161         int qqq = 0;
162         for(int i = 0;i < ss;i ++)
163         {
164             if(str.equals(s[ss]))
165             {
166                 qqq = 1;
167                 break;
168             }
169         }
170         return qqq;
171     }
172     //整数加法
173     public static int intjia(int a,int b)
174     {
175         int c;
176         c = a + b;
177         return c;
178     }
179     //整数减法
180     public static int intjian(int a,int b)
181     {
182         int c;
183         c = a + b;
184         return c;
185     }
186     //整数乘法
187     public static int intcheng(int a,int b)
188     {
189         int c;
190         c = a * b;
191         return c;
192     }
193     //整数除法
194     public static int intchu(int a,int b)
195     {
196         int c;
197         c = a / b;
198         return c;
199     }
200     public static int SuiJileixing()
201     {
202         int flag = (int)(Math.random()*2);
203         return flag;
204     }
205     public static int SuiJi1()
206     {
207         int a;
208         a = (int)(Math.random()*100);
209         return a;
210     }
211     public static int SuiJiyunsuanfu()
212     {
213         int a;
214         a = (int) (Math.random()*4);
215         return a;
216     }
217     public static void show(double a,double b,int k)
218     {
219         double c ;
220         if(k == 0)
221         {
222              c = a + b;
223             System.out.println((int)c);
224         }
225         if(k == 1)
226         {
227             c = (int) (a - b);
228             System.out.println((int)c);
229         }
230         if(k == 2)
231         {
232             c = (int) (a * b);
233             System.out.println((int)c);
234         }
235         if(k == 3)
236         {
237             c = (int) (a / b);
238             System.out.println((int)c);
239         }
240     }
241 
242 }

技术分享技术分享

 

软件工程概论作业02