软件工程个人作业01

程序设计思想:

刚开始建立两个类(真假分数判断未成功)和主函数,一个为数类,进行对数字的随机提取,以及分数的计算,其中由于涉及分数,我用的是四个数字组成两个分数的设计方式;另一个为判断重复类,就是对前后两个数以及运算符号是否完全相等得判断。最后在主函数中直接加以调用以及运行即可。

源代码:

 1 package test;
 2 import java.lang.*;
 3 import java.util.*;
 4 
 5 public class test {
 6     /*public static   void zhenfenshu(Shu A){
 7         if(A.a/A.d>1||A.b/A.e>1)
 8         {
 9             A.shu();
10         }
11     }*/
12     public static Boolean chachong1(Shu x,Shu y){
13         if(x.a/x.d==y.a/y.d&&x.b/x.e==y.b/y.e&&x.c==y.c)
14         {
15             return true;
16         }
17         else if(x.a/x.d==y.d/y.e&&x.b/x.e==y.a/y.d&&x.c==y.c)
18         {
19             return true;
20         }
21         else{return false;}
22     }
23 
24     public static void main(String args[]){
25         int i;
26         System.out.println("请输入要输出的题数:");
27         Scanner num=new Scanner(System.in);
28         int n = num.nextInt();
29         Shu s[]=new Shu [n];    
30             for(i=0;i<n;i++){
31                 s[i]=new Shu();
32                 boolean ss=true;
33                 //zhenfenshu(s[i]);
34                 while(ss){
35                     ss=false;
36                     s[i].shu();
37                     for(int j=0;j<i;j++){
38                         if(chachong1(s[i],s[j])){
39                             ss=true;
40                         }
41                     }
42                 }
43             }
44             for(i=0;i<n;i++)
45             {
46                 s[i].show();
47             }
48             }
49 }
50 class Shu{
51     int a,b,c,d,e;
52     public  void shu(){
53         a = (int)(Math.random()*100);
54         d = (int)(Math.random()*100);
55         e = (int)(Math.random()*100);
56         b = (int)(Math.random()*100);
57         c = (int)(Math.random()*3);
58     }
59     public void show(){
60         if(c==0) System.out.println(a+"/"+d+"+"+b+"/"+e);
61         if(c==1) System.out.println(a+"/"+d+"-"+b+"/"+e);
62         if(c==2) System.out.println(a+"/"+d+"*"+b+"/"+e);
63         if(c==3) System.out.println(a+"/"+d+"/"+b+"/"+e);
64     }
65 }

结果截图:

上课未完成的原因:

最主要的是在家没有练习编代码,来学之后刚开始就自己编写,对上学期的知识有些遗漏,例如数组不会编写,类建立的时候没有那么熟悉。

原文地址:https://www.cnblogs.com/bai123/p/6489372.html