作业五:封装与测试
1 import java.awt.Dimension; 2 import java.awt.FlowLayout; 3 import java.awt.GridLayout; 4 import java.awt.Toolkit; 5 import java.awt.event.ActionEvent; 6 import java.awt.event.ActionListener; 7 8 import javax.swing.JButton; 9 import javax.swing.JFrame; 10 import javax.swing.JLabel; 11 import javax.swing.JOptionPane; 12 import javax.swing.JPanel; 13 import javax.swing.JTextField; 14 import javax.swing.Timer; 15 16 public class Jiemian extends JFrame implements ActionListener{ 17 18 /** 19 * @param args 20 */ 21 Jisuanlei JISUAN=new Jisuanlei(); 22 private Timer tmr; 23 String result; 24 int dadui=0; 25 JLabel L1=new JLabel("设置时间:"); 26 JLabel L2=new JLabel("实际用时:"); 27 JLabel L3=new JLabel("输入你想要的题数(最多1--5):"); 28 JLabel L4=new JLabel("你答对的题目数有:"); 29 JLabel L5=new JLabel("温馨提示:"); 30 JLabel L6=new JLabel("="); 31 JLabel Q1=new JLabel(" "); 32 JLabel Q2=new JLabel(" "); 33 JLabel Q3=new JLabel(" "); 34 JLabel Q4=new JLabel(" "); 35 JTextField T1=new JTextField(10); 36 JTextField T2=new JTextField(10); 37 JTextField T3=new JTextField(3); 38 JTextField T4=new JTextField(3); 39 JTextField T5=new JTextField(3); 40 JTextField T6=new JTextField(3); 41 JTextField T7=new JTextField(3); 42 JTextField T8=new JTextField(20); 43 JTextField T9=new JTextField(3); 44 45 JButton B1=new JButton("确定"); 46 JButton B5=new JButton("确定"); 47 JButton B2=new JButton("出题"); 48 JButton B3=new JButton("确定答案!"); 49 JButton B4=new JButton("下一题!"); 50 51 52 53 54 55 public Jiemian(){ 56 super("CHENGXU"); 57 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 58 this.setPreferredSize(new Dimension(300,600)); 59 this.getContentPane(); 60 this.pack(); 61 FlowLayout layout = new FlowLayout(FlowLayout.CENTER,5,20); 62 this.setLayout(layout); 63 this.add(L1);this.add(T1);this.add(B1);this.add(L2);this.add(T2);this.add(Q1); 64 this.add(L3);this.add(T3);this.add(B5); 65 this.add(B2);this.add(B2); 66 this.add(T4);this.add(T5);this.add(T6);this.add(L6);this.add(T7); 67 this.add(B3);this.add(B4);this.add(Q2); 68 this.add(L5);this.add(T8); 69 this.add(L4);this.add(T9);this.add(Q3); 70 71 B1.addActionListener(this); 72 73 B2.addActionListener(this); 74 75 B3.addActionListener(this); 76 Timer tmr = new Timer(1000, this);//间隔1秒 77 this.tmr = tmr;//添加时间 78 B4.addActionListener(this); 79 80 B5.addActionListener(this); 81 82 83 int width = Toolkit.getDefaultToolkit().getScreenSize().width; //把框在屏幕中间显示 84 int height = Toolkit.getDefaultToolkit().getScreenSize().height; 85 this.setLocation(width / 2 - 300, height / 2 - 200); 86 87 this.setVisible(true); 88 this.setResizable(false); 89 90 91 92 } 93 94 95 96 97 public void actionPerformed(ActionEvent e) 98 { 99 if(e.getSource()==B1)//当获取的资源是按钮1时 100 { 101 try 102 { 103 T2.setText(String.valueOf(T1.getText()));//在显示时间框里显示以获取的时间 104 105 int n1=120,n2=5; 106 if(n1<(Integer.parseInt(T2.getText()))) 107 {//当设置时间超过120秒,弹出对话框 108 JOptionPane.showMessageDialog(null, "时间不能超过120秒!"); 109 this.setVisible(false); 110 } 111 if(n2<(Integer.parseInt(T3.getText()))) 112 {//当选择题目个数超过5个,弹出对话框 113 JOptionPane.showMessageDialog(null, "选择题数不能超过五个!"); 114 this.setVisible(false); 115 } 116 tmr.start();//开始计时 117 } 118 catch(NullPointerException o) 119 { 120 121 } 122 //suijishu();//调用产生随机数题目 123 // startTime= System.currentTimeMillis(); //获取开始时间 124 T2.setText(String.valueOf(T1.getText())); 125 } 126 else{ 127 int m = Integer.parseInt(T2.getText()); 128 m--; 129 T2.setText("" + m); 130 if (m <= 0) 131 { 132 tmr.stop(); 133 JOptionPane.showMessageDialog(null, "超出答题时间!"); 134 this.setVisible(false); 135 } 136 } 137 138 139 if(e.getSource()==B5)//当获取的资源是按钮1时 140 { 141 int num=(int) Double.parseDouble(T3.getText()); 142 System.out.println(num); 143 144 if(5<(Integer.parseInt(T3.getText()))) 145 {//当选择题目个数超过5个,弹出对话框 146 JOptionPane.showMessageDialog(null, "选择题数不能超过五个!"); 147 this.setVisible(false); 148 } 149 150 } 151 152 153 154 155 if(e.getSource()==B2)//当获取的资源是按钮1时 156 { 157 int fuhao1=(int) (Math.random()*11/3+1); 158 switch (fuhao1) 159 { 160 case 1: 161 { 162 int leixing=(int) (Math.random()*8/3+1);//1表示整数,2表示分数,3表示阶乘; 163 switch(leixing) 164 { 165 case 1: 166 { 167 /*int shu1=(int) (Math.random()*10+1); 168 int shu2=(int) (Math.random()*10+1); 169 T4.setText(String.valueOf(shu1)); 170 T6.setText(String.valueOf(shu2)); 171 T5.setText(String.valueOf("+")); 172 result=String.valueOf(shu1+shu2);*/ 173 Jisuanlei.Jiahaozhengshuyunsuan( T4,T6, T5, result); 174 if(e.getSource()==B3) 175 { 176 if(result.equals(T7.getText())) 177 { 178 T8.setText("答案正确!"); 179 } 180 else 181 T8.setText("答案错误!正确答案是"+result); 182 dadui++; 183 } 184 185 }break; 186 case 2: 187 { 188 /*int shu1=(int) (Math.random()*10+1); 189 int shu2=(int) (Math.random()*10+1); 190 int shu3=(int) (Math.random()*10+1); 191 int shu4=(int) (Math.random()*10+1); 192 if(shu1>shu2) 193 { 194 int temp=shu1; 195 shu1=shu2; 196 shu2=temp; 197 } 198 if(shu3>shu4) 199 { 200 int temp=shu3; 201 shu3=shu4; 202 shu4=temp; 203 } 204 205 T4.setText(String.valueOf(shu1+"/"+shu2)); 206 T6.setText(String.valueOf(shu3+"/"+shu4)); 207 T5.setText(String.valueOf("+")); 208 int res1=(shu1*shu4)+(shu2*shu3); 209 int res2=shu2*shu4; 210 int pan=0; 211 if(res1>res2) 212 { 213 pan=res2; 214 } 215 else 216 { 217 pan=res1; 218 } 219 for(int i=pan;i>0;i--) 220 { 221 if(res1%pan==0&&res2%pan==0) 222 { 223 res1=res1/pan; 224 res2=res2/pan; 225 if(res1>res2) 226 { 227 pan=res2; 228 } 229 else 230 { 231 pan=res1; 232 } 233 i=pan; 234 } 235 } 236 237 result=String.valueOf(shu1+"/"+shu2);*/ 238 Jisuanlei.Jiahaofenshuyunsuan( T4,T6, T5, result); 239 if(e.getSource()==B3) 240 { 241 if(result.equals(T7.getText())) 242 { 243 T8.setText("答案正确!"); 244 } 245 else 246 T8.setText("答案错误!正确答案是"+result); 247 dadui++; 248 } 249 }break; 250 case 3: 251 { 252 253 /*int shu1=(int) (Math.random()*9+1); 254 int res1=shu1; 255 T6.setText(String.valueOf("!"+shu1)); 256 for(int i=shu1-1;i>0;i--) 257 { 258 res1=res1*i; 259 } 260 result=String.valueOf(res1);*/ 261 Jisuanlei.Jiahaojieshengyunsuan( T4,T6, T5, result); 262 if(e.getSource()==B3) 263 { 264 if(result.equals(T7.getText())) 265 { 266 T8.setText("答案正确!"); 267 } 268 else 269 T8.setText("答案错误!正确答案是"+result); 270 dadui++; 271 } 272 }break; 273 274 } 275 276 }break; 277 case 2: 278 { 279 int leixing=(int) (Math.random()*8/3+1);//1表示整数,2表示分数,3表示阶乘; 280 switch(leixing) 281 { 282 case 1: 283 { 284 /*int shu1=(int) (Math.random()*10+1); 285 int shu2=(int) (Math.random()*10+1); 286 T4.setText(String.valueOf(shu1)); 287 T6.setText(String.valueOf(shu2)); 288 T5.setText(String.valueOf("-")); 289 result=String.valueOf(shu1-shu2);*/ 290 Jisuanlei.Jianhaozhengshuyunsuan(T4,T6,T5,result); 291 if(e.getSource()==B3) 292 { 293 if(result.equals(T7.getText())) 294 { 295 T8.setText("答案正确!"); 296 } 297 else 298 T8.setText("答案错误!正确答案是"+result); 299 dadui++; 300 } 301 }break; 302 case 2: 303 { 304 /*int shu1=(int) (Math.random()*10+1); 305 int shu2=(int) (Math.random()*10+1); 306 int shu3=(int) (Math.random()*10+1); 307 int shu4=(int) (Math.random()*10+1); 308 if(shu1>shu2) 309 { 310 int temp=shu1; 311 shu1=shu2; 312 shu2=temp; 313 } 314 if(shu3>shu4) 315 { 316 int temp=shu3; 317 shu3=shu4; 318 shu4=temp; 319 } 320 321 T4.setText(String.valueOf(shu1+"/"+shu2)); 322 T6.setText(String.valueOf(shu3+"/"+shu4)); 323 T5.setText(String.valueOf("-")); 324 int res1=(shu1*shu4)-(shu2*shu3); 325 int res2=shu2*shu4; 326 int pan=0; 327 if(res1>res2) 328 { 329 pan=res2; 330 } 331 else 332 { 333 pan=res1; 334 } 335 for(int i=pan;i>0;i--) 336 { 337 if(res1%pan==0&&res2%pan==0) 338 { 339 res1=res1/pan; 340 res2=res2/pan; 341 if(res1>res2) 342 { 343 pan=res2; 344 } 345 else 346 { 347 pan=res1; 348 } 349 i=pan; 350 } 351 } 352 353 result=String.valueOf(shu1+"/"+shu2);*/ 354 Jisuanlei.Jianhaofenshuyunsuan(T4,T6,T5,result); 355 if(e.getSource()==B3) 356 { 357 if(result.equals(T7.getText())) 358 { 359 T8.setText("答案正确!"); 360 } 361 else 362 T8.setText("答案错误!正确答案是"+result); 363 dadui++; 364 } 365 }break; 366 case 3: 367 { 368 369 /*int shu1=(int) (Math.random()*9+1); 370 int res1=shu1; 371 T6.setText(String.valueOf("!"+shu1)); 372 for(int i=shu1-1;i>0;i--) 373 { 374 res1=res1*i; 375 } 376 result=String.valueOf(res1);*/ 377 Jisuanlei.Jianhaofenshuyunsuan(T4,T6,T5,result); 378 if(e.getSource()==B3) 379 { 380 if(result.equals(T7.getText())) 381 { 382 T8.setText("答案正确!"); 383 } 384 else 385 T8.setText("答案错误!正确答案是"+result); 386 dadui++; 387 } 388 }break; 389 390 } 391 392 }break; 393 case 3: 394 { 395 int leixing=(int) (Math.random()*8/3+1);//1表示整数,2表示分数,3表示阶乘; 396 switch(leixing) 397 { 398 case 1: 399 { 400 /*int shu1=(int) (Math.random()*10+1); 401 int shu2=(int) (Math.random()*10+1); 402 T4.setText(String.valueOf(shu1)); 403 T6.setText(String.valueOf(shu2)); 404 T5.setText(String.valueOf("*")); 405 result=String.valueOf(shu1*shu2);*/ 406 Jisuanlei.shenghaozhengshuyunsuan(T4,T6,T5,result); 407 if(e.getSource()==B3) 408 { 409 if(result.equals(T7.getText())) 410 { 411 T8.setText("答案正确!"); 412 } 413 else 414 T8.setText("答案错误!正确答案是"+result); 415 dadui++; 416 } 417 }break; 418 case 2: 419 { 420 /*int shu1=(int) (Math.random()*10+1); 421 int shu2=(int) (Math.random()*10+1); 422 int shu3=(int) (Math.random()*10+1); 423 int shu4=(int) (Math.random()*10+1); 424 if(shu1>shu2) 425 { 426 int temp=shu1; 427 shu1=shu2; 428 shu2=temp; 429 } 430 if(shu3>shu4) 431 { 432 int temp=shu3; 433 shu3=shu4; 434 shu4=temp; 435 } 436 437 T4.setText(String.valueOf(shu1+"/"+shu2)); 438 T6.setText(String.valueOf(shu4+"/"+shu3)); 439 T5.setText(String.valueOf("*")); 440 int res1=(shu1)*(shu3); 441 int res2=shu2*shu4; 442 int pan=0; 443 if(res1>res2) 444 { 445 pan=res2; 446 } 447 else 448 { 449 pan=res1; 450 } 451 for(int i=pan;i>0;i--) 452 { 453 if(res1%pan==0&&res2%pan==0) 454 { 455 res1=res1/pan; 456 res2=res2/pan; 457 if(res1>res2) 458 { 459 pan=res2; 460 } 461 else 462 { 463 pan=res1; 464 } 465 i=pan; 466 } 467 } 468 469 result=String.valueOf(shu1+"/"+shu2);*/ 470 Jisuanlei.shenghaofenshuyunsuan(T4,T6,T5,result); 471 if(e.getSource()==B3) 472 { 473 if(result.equals(T7.getText())) 474 { 475 T8.setText("答案正确!"); 476 } 477 else 478 T8.setText("答案错误!正确答案是"+result); 479 dadui++; 480 } 481 }break; 482 case 3: 483 { 484 485 /*int shu1=(int) (Math.random()*9+1); 486 int res1=shu1; 487 T6.setText(String.valueOf("!"+shu1)); 488 for(int i=shu1-1;i>0;i--) 489 { 490 res1=res1*i; 491 } 492 result=String.valueOf(res1);*/ 493 Jisuanlei.shenghaojieshengyunsuan(T4,T6,T5,result); 494 if(e.getSource()==B3) 495 { 496 if(result.equals(T7.getText())) 497 { 498 T8.setText("答案正确!"); 499 } 500 else 501 T8.setText("答案错误!正确答案是"+result); 502 dadui++; 503 } 504 }break; 505 506 } 507 508 }break; 509 case 4: 510 { 511 int leixing=(int) (Math.random()*8/3+1);//1表示整数,2表示分数,3表示阶乘; 512 switch(leixing) 513 { 514 case 1: 515 { 516 /*int shu1=(int) (Math.random()*10+1); 517 int shu2=(int) (Math.random()*10+1); 518 T4.setText(String.valueOf(shu1)); 519 T6.setText(String.valueOf(shu2)); 520 T5.setText(String.valueOf("/")); 521 result=String.valueOf(shu1/shu2);*/ 522 Jisuanlei.chuhaozhengshuyunsuan(T4,T6,T5,result); 523 if(e.getSource()==B3) 524 { 525 if(result.equals(T7.getText())) 526 { 527 T8.setText("答案正确!"); 528 } 529 else 530 T8.setText("答案错误!正确答案是"+result); 531 dadui++; 532 } 533 }break; 534 case 2: 535 { 536 /*int shu1=(int) (Math.random()*10+1); 537 int shu2=(int) (Math.random()*10+1); 538 int shu3=(int) (Math.random()*10+1); 539 int shu4=(int) (Math.random()*10+1); 540 if(shu1>shu2) 541 { 542 int temp=shu1; 543 shu1=shu2; 544 shu2=temp; 545 } 546 if(shu3>shu4) 547 { 548 int temp=shu3; 549 shu3=shu4; 550 shu4=temp; 551 } 552 553 T4.setText(String.valueOf(shu1+"/"+shu2)); 554 T6.setText(String.valueOf(shu3+"/"+shu4)); 555 T5.setText(String.valueOf("/")); 556 int res1=shu1*shu4; 557 int res2=shu2*shu3; 558 int pan=0; 559 if(res1>res2) 560 { 561 pan=res2; 562 } 563 else 564 { 565 pan=res1; 566 } 567 for(int i=pan;i>0;i--) 568 { 569 if(res1%pan==0&&res2%pan==0) 570 { 571 res1=res1/pan; 572 res2=res2/pan; 573 if(res1>res2) 574 { 575 pan=res2; 576 } 577 else 578 { 579 pan=res1; 580 } 581 i=pan; 582 } 583 } 584 585 result=String.valueOf(shu1+"/"+shu2);*/ 586 Jisuanlei.chuhaofenshuyunsuan(T4,T6,T5,result); 587 if(e.getSource()==B3) 588 { 589 if(result.equals(T7.getText())) 590 { 591 T8.setText("答案正确!"); 592 } 593 else 594 T8.setText("答案错误!正确答案是"+result); 595 dadui++; 596 } 597 }break; 598 case 3: 599 { 600 601 /*int shu1=(int) (Math.random()*9+1); 602 int res1=shu1; 603 T6.setText(String.valueOf("!"+shu1)); 604 for(int i=shu1-1;i>0;i--) 605 { 606 res1=res1*i; 607 } 608 result=String.valueOf(res1);*/ 609 Jisuanlei.chuhaojieshengyunsuan(T4,T6,T5,result); 610 if(e.getSource()==B3) 611 { 612 if(result.equals(T7.getText())) 613 { 614 T8.setText("答案正确!"); 615 } 616 else 617 T8.setText("答案错误!正确答案是"+result); 618 dadui++; 619 } 620 }break; 621 622 } 623 624 }break; 625 } 626 627 } 628 629 630 631 } 632 633 634 635 636 637 638 public static void main(String[] args) { 639 // TODO Auto-generated method stub 640 new Jiemian(); 641 642 643 } 644 645 } 主界面等程序代码
1 import javax.swing.JButton; 2 import javax.swing.JTextField; 3 4 5 public class Jisuanlei { 6 7 /** 8 * @param args 9 */ 10 /* public static void main(String[] args) { 11 // TODO Auto-generated method stub 12 13 14 } 15 */ 16 Jisuanlei (){}; 17 static void Jiahaozhengshuyunsuan(JTextField T4,JTextField T6,JTextField T5,String result) { 18 int shu1=(int) (Math.random()*10+1); 19 int shu2=(int) (Math.random()*10+1); 20 T4.setText(String.valueOf(shu1)); 21 T6.setText(String.valueOf(shu2)); 22 T5.setText(String.valueOf("+")); 23 result=String.valueOf(shu1+shu2); 24 25 26 } 27 static void Jiahaofenshuyunsuan(JTextField T4,JTextField T6,JTextField T5,String result) { 28 int shu1=(int) (Math.random()*10+1); 29 int shu2=(int) (Math.random()*10+1); 30 int shu3=(int) (Math.random()*10+1); 31 int shu4=(int) (Math.random()*10+1); 32 if(shu1>shu2) 33 { 34 int temp=shu1; 35 shu1=shu2; 36 shu2=temp; 37 } 38 if(shu3>shu4) 39 { 40 int temp=shu3; 41 shu3=shu4; 42 shu4=temp; 43 } 44 45 T4.setText(String.valueOf(shu1+"/"+shu2)); 46 T6.setText(String.valueOf(shu3+"/"+shu4)); 47 T5.setText(String.valueOf("+")); 48 int res1=(shu1*shu4)+(shu2*shu3); 49 int res2=shu2*shu4; 50 int pan=0; 51 if(res1>res2) 52 { 53 pan=res2; 54 } 55 else 56 { 57 pan=res1; 58 } 59 for(int i=pan;i>0;i--) 60 { 61 if(res1%pan==0&&res2%pan==0) 62 { 63 res1=res1/pan; 64 res2=res2/pan; 65 if(res1>res2) 66 { 67 pan=res2; 68 } 69 else 70 { 71 pan=res1; 72 } 73 i=pan; 74 } 75 } 76 77 result=String.valueOf(shu1+"/"+shu2); 78 79 80 } 81 82 static void Jiahaojieshengyunsuan(JTextField T4,JTextField T6,JTextField T5,String result) { 83 int shu1=(int) (Math.random()*9+1); 84 int res1=shu1; 85 T6.setText(String.valueOf("!"+shu1)); 86 for(int i=shu1-1;i>0;i--) 87 { 88 res1=res1*i; 89 } 90 result=String.valueOf(res1); 91 92 } 93 94 static void Jianhaozhengshuyunsuan(JTextField T4,JTextField T6,JTextField T5,String result) { 95 int shu1=(int) (Math.random()*10+1); 96 int shu2=(int) (Math.random()*10+1); 97 T4.setText(String.valueOf(shu1)); 98 T6.setText(String.valueOf(shu2)); 99 T5.setText(String.valueOf("-")); 100 result=String.valueOf(shu1-shu2); 101 } 102 103 static void Jianhaofenshuyunsuan(JTextField T4,JTextField T6,JTextField T5,String result) { 104 int shu1=(int) (Math.random()*10+1); 105 int shu2=(int) (Math.random()*10+1); 106 int shu3=(int) (Math.random()*10+1); 107 int shu4=(int) (Math.random()*10+1); 108 if(shu1>shu2) 109 { 110 int temp=shu1; 111 shu1=shu2; 112 shu2=temp; 113 } 114 if(shu3>shu4) 115 { 116 int temp=shu3; 117 shu3=shu4; 118 shu4=temp; 119 } 120 121 T4.setText(String.valueOf(shu1+"/"+shu2)); 122 T6.setText(String.valueOf(shu3+"/"+shu4)); 123 T5.setText(String.valueOf("-")); 124 int res1=(shu1*shu4)-(shu2*shu3); 125 int res2=shu2*shu4; 126 int pan=0; 127 if(res1>res2) 128 { 129 pan=res2; 130 } 131 else 132 { 133 pan=res1; 134 } 135 for(int i=pan;i>0;i--) 136 { 137 if(res1%pan==0&&res2%pan==0) 138 { 139 res1=res1/pan; 140 res2=res2/pan; 141 if(res1>res2) 142 { 143 pan=res2; 144 } 145 else 146 { 147 pan=res1; 148 } 149 i=pan; 150 } 151 } 152 153 result=String.valueOf(shu1+"/"+shu2); 154 } 155 156 static void Jianhaojieshengyunsuan(JTextField T4,JTextField T6,JTextField T5,String result) { 157 int shu1=(int) (Math.random()*9+1); 158 int res1=shu1; 159 T6.setText(String.valueOf("!"+shu1)); 160 for(int i=shu1-1;i>0;i--) 161 { 162 res1=res1*i; 163 } 164 result=String.valueOf(res1); 165 } 166 167 static void shenghaozhengshuyunsuan(JTextField T4,JTextField T6,JTextField T5,String result) { 168 int shu1=(int) (Math.random()*10+1); 169 int shu2=(int) (Math.random()*10+1); 170 T4.setText(String.valueOf(shu1)); 171 T6.setText(String.valueOf(shu2)); 172 T5.setText(String.valueOf("*")); 173 result=String.valueOf(shu1*shu2); 174 } 175 176 static void shenghaofenshuyunsuan(JTextField T4,JTextField T6,JTextField T5,String result) { 177 int shu1=(int) (Math.random()*10+1); 178 int shu2=(int) (Math.random()*10+1); 179 int shu3=(int) (Math.random()*10+1); 180 int shu4=(int) (Math.random()*10+1); 181 if(shu1>shu2) 182 { 183 int temp=shu1; 184 shu1=shu2; 185 shu2=temp; 186 } 187 if(shu3>shu4) 188 { 189 int temp=shu3; 190 shu3=shu4; 191 shu4=temp; 192 } 193 194 T4.setText(String.valueOf(shu1+"/"+shu2)); 195 T6.setText(String.valueOf(shu4+"/"+shu3)); 196 T5.setText(String.valueOf("*")); 197 int res1=(shu1)*(shu3); 198 int res2=shu2*shu4; 199 int pan=0; 200 if(res1>res2) 201 { 202 pan=res2; 203 } 204 else 205 { 206 pan=res1; 207 } 208 for(int i=pan;i>0;i--) 209 { 210 if(res1%pan==0&&res2%pan==0) 211 { 212 res1=res1/pan; 213 res2=res2/pan; 214 if(res1>res2) 215 { 216 pan=res2; 217 } 218 else 219 { 220 pan=res1; 221 } 222 i=pan; 223 } 224 } 225 226 result=String.valueOf(shu1+"/"+shu2); 227 } 228 229 static void shenghaojieshengyunsuan(JTextField T4,JTextField T6,JTextField T5,String result) { 230 int shu1=(int) (Math.random()*9+1); 231 int res1=shu1; 232 T6.setText(String.valueOf("!"+shu1)); 233 for(int i=shu1-1;i>0;i--) 234 { 235 res1=res1*i; 236 } 237 result=String.valueOf(res1); 238 } 239 240 static void chuhaozhengshuyunsuan(JTextField T4,JTextField T6,JTextField T5,String result) { 241 int shu1=(int) (Math.random()*10+1); 242 int shu2=(int) (Math.random()*10+1); 243 T4.setText(String.valueOf(shu1)); 244 T6.setText(String.valueOf(shu2)); 245 T5.setText(String.valueOf("/")); 246 result=String.valueOf(shu1/shu2); 247 } 248 249 static void chuhaofenshuyunsuan(JTextField T4,JTextField T6,JTextField T5,String result) { 250 int shu1=(int) (Math.random()*10+1); 251 int shu2=(int) (Math.random()*10+1); 252 int shu3=(int) (Math.random()*10+1); 253 int shu4=(int) (Math.random()*10+1); 254 if(shu1>shu2) 255 { 256 int temp=shu1; 257 shu1=shu2; 258 shu2=temp; 259 } 260 if(shu3>shu4) 261 { 262 int temp=shu3; 263 shu3=shu4; 264 shu4=temp; 265 } 266 267 T4.setText(String.valueOf(shu1+"/"+shu2)); 268 T6.setText(String.valueOf(shu3+"/"+shu4)); 269 T5.setText(String.valueOf("/")); 270 int res1=shu1*shu4; 271 int res2=shu2*shu3; 272 int pan=0; 273 if(res1>res2) 274 { 275 pan=res2; 276 } 277 else 278 { 279 pan=res1; 280 } 281 for(int i=pan;i>0;i--) 282 { 283 if(res1%pan==0&&res2%pan==0) 284 { 285 res1=res1/pan; 286 res2=res2/pan; 287 if(res1>res2) 288 { 289 pan=res2; 290 } 291 else 292 { 293 pan=res1; 294 } 295 i=pan; 296 } 297 } 298 299 result=String.valueOf(shu1+"/"+shu2); 300 } 301 302 static void chuhaojieshengyunsuan(JTextField T4,JTextField T6,JTextField T5,String result) { 303 int shu1=(int) (Math.random()*9+1); 304 int res1=shu1; 305 T6.setText(String.valueOf("!"+shu1)); 306 for(int i=shu1-1;i>0;i--) 307 { 308 res1=res1*i; 309 } 310 result=String.valueOf(res1); 311 } 312 313 314 315 316 } 计算类代码
结对同伴 :43 陈友沛
同伴博客:http://www.cnblogs.com/peipeipei/