zoukankan      html  css  js  c++  java
  • 软件工程个人作业02

    设计思路

     1 排除重复

     2 进行选择数量n

    3判断是否有除法

      3.2输入你的选择,有输入(1),无输入(0)

    4运算没有乘除

        4.2进行选择"是否有负数,有输入(1),无输入(0)“的运算

        4.3 for循环

             4.3.1随机分配整数

             4.3.2随机分配运算符

             4.3.3判断整数,分数运算

                    4.3.3--1判断负数选择,进行整数运算

             4.3.4   分数运算

                   4.3.4---2       构造函数求最大公约数

                   1.3.4---3       构造最简分数进行运算

    5  运算有乘除法运算

        5.2进行选择是否有余数运算,

        5.3没有余数的运算,包括加减法运算

         5.4for循环

              5.5--1判断选择的是没有余数

                      5.5.2 随机分配整数

                      5.5.2随机分配运算符

                     5.5.3判断是否进行多项式运算

                              5.5.3--2不存在多项式运算

                              5.5.3--3多项式运算

                                        5.5.3 ---3---2随机分为2---5项的类别,    

             5.5 --2判断选择的是有余数的四则运算,包括加减法运算,和没有余数运算

                     

                      5.5.1 随机分配整数

                      5.5.2随机分配运算符

                     5.5.3判断是否进行多项式运算

                              5.5.3--2不存在多项式运算

                              5.5.3--3多项式运算

                                        5.5.3 ---3---2随机分为2---5项的类别,  

                          

          

    实验代码

      1 package basic;
      2 //lvzekun 2016/3/19
      3 import java.util.Scanner;
      4 
      5 public class BasicArithmetic {
      6     public static void main(String []args){
      7         //定制数量
      8         System.out.println("输入定制数量 :n:");
      9         Scanner input=new Scanner(System.in);
     10         int n=input.nextInt();
     11         /*System.out.println("定制数量 :n"+n);*/
     12         
     13         
     14         
     15         //判断是否乘除
     16             System.out.println("是否有乘除,有输入(1),无输入(0)");
     17             Scanner scan=new Scanner(System.in);
     18             int j=scan.nextInt();
     19             
     20         if(j==0)//无乘除
     21         {    
     22             System.out.println("是否有负数,有输入(1),无输入(0)");
     23             Scanner scanner=new Scanner(System.in);
     24             int j2=scanner.nextInt();
     25             
     26         for(int i=0;i<n;i++)
     27         {//随机分配运算符号
     28             System.out.println("题目");
     29             //随机生成数字a,b(0--100);
     30             int a=(int)(Math.random()*100);
     31             int b=(int)(Math.random()*100);
     32             
     33             
     34                  String  s[]={"+","-"};
     35                     int c=(int)(Math.random()*2);
     36                     String d=s[c];
     37                     
     38                  //判断整数分数
     39                  int k=(int)(Math.random()*2)+1;
     40                  
     41                  if(k==1)//整数运算
     42                  {
     43                      if(j2==0)//说明没有负数
     44                          
     45                      System.out.println(a+d+b+"=");
     46                      
     47                      else//有复数运算
     48                      {   //分为整数运算,和负整数运算
     49                          int j22=(int)(Math.random()*2);
     50                          if(j22==1)
     51                          System.out.println(a+d+"("+"-"+b+")"+"=");
     52                          else
     53                              System.out.println(a+d+b+"=");
     54                              
     55                      }
     56                  }
     57                  else
     58                  {
     59                     
     60                       int gcd=gcd(a,b);//求最大公约数
     61                      
     62                         int num1=(int)(Math.random()*98)+1;
     63                          int num2=(int)(Math.random()*98)+1;
     64                          int gcd2=gcd(num1,num2);
     65                       System.out.println(a/gcd+"/"+b/gcd+d+num1/gcd2+"/"+num2/gcd2+"="); 
     66                         
     67                  }
     68                  
     69         
     70         }
     71         }
     72         
     73         //有乘除运算
     74         if(j==1)
     75         {
     76         
     77             //判断是否有余数的除法运算j3
     78             System.out.println("是否有余数,有输入(1),无输入(0)");
     79             Scanner scanner=new Scanner(System.in);
     80             int j3=scanner.nextInt();
     81             
     82             //进行循环运算
     83             for(int i=0;i<n;i++)
     84             {    
     85                 
     86                 
     87                 //判断是否有括号(最多可以支持十个数参与计算);
     88             
     89                   int j4=(int)(Math.random()*6+2);
     90             
     91                 //分配运算符号
     92                 String  s[]={"+","-","*","/"};
     93                 int c=(int)(Math.random()*4);
     94                 String d=s[c];
     95                 
     96                 //随机生成数字a,b(0--100);
     97                 int a=(int)(Math.random()*100)+1;
     98                 int b=(int)(Math.random()*100)+1;
     99                 
    100                 
    101                //随机运算是除法时候判断是否有余数
    102                 if(j3==0)//不存在余数的运算
    103                 {
    104                     
    105                         int j42=(int)(Math.random()*2);
    106                         if(j42==0)//不存在多项式运算
    107                         System.out.println(2*a+d+a+"=");
    108                         
    109                         else
    110                         {
    111                             
    112                             String  s2[]={"*","/"};
    113                             int c2=(int)(Math.random()*2);
    114                             String d2=s2[c2];
    115                             
    116                             if(j4==2)
    117                             {
    118                                 System.out.println("("+b+d2+a+")"+d2+"("+2*a+d2+b+")"+"=");
    119                             }
    120                             if(j4==3)
    121                             {
    122                                 
    123                                 System.out.println("("+b+d2+a+")"+d+"("+2*a+d2+b+")"+d+"("+b*2+d2+a+")"+"=");
    124                             }
    125                             if(j4==4){
    126                                 int w=gcd(a,b);
    127                                 System.out.println("("+b+d2+a+")"+d+"("+2*a+d2+b+")"+d+"("+b*2+d2+a+")"+d+
    128                                         "("+a/w+d2+b+")"+"=");
    129                             }    
    130                             if(j4==5)
    131                             {
    132                                 int w=gcd(a,b);
    133                                 System.out.println("("+b+d2+a+")"+d+"("+2*a+d2+b+")"+d+"("+b*2+d2+a+")"+d+"("+
    134                             a/w+d2+b+")"+d+"("+a+d2+b/w+")"+"=");
    135                             }
    136                         }
    137                         
    138                         
    139                     }
    140                     else 
    141                     {
    142                         if(a/b!=0)
    143                         {
    144                             int j42=(int)(Math.random()*2);
    145                             if(j42==0)//不存在多项式运算
    146                             System.out.println(2*a+d+a+"=");
    147                             else{
    148 
    149                                 String  s2[]={"*","/"};
    150                                 int c2=(int)(Math.random()*2);
    151                                 String d2=s2[c2];
    152                                 
    153                                 if(j4==2)
    154                                 {
    155                                     System.out.println("("+b+d2+a+")"+d2+"("+2*a+d2+b+")"+"+");
    156                                 }
    157                                 if(j4==3)
    158                                 {
    159                                     
    160                                     System.out.println("("+b+d2+a+")"+d+"("+2*a+d2+b+")"+d+"("+b*2+d2+a+")"+"=");
    161                                 }
    162                                 if(j4==4){
    163                                     int w=gcd(a,b);
    164                                     System.out.println("("+b+d2+a+")"+d+"("+2*a+d2+b+")"+d+"("+b*2+d2+a+")"+d+
    165                                             "("+a/w+d2+b+")"+"=");
    166                                 }    
    167                                 if(j4==5)
    168                                 {
    169                                     int w=gcd(a,b);
    170                                     System.out.println("("+b+d2+a+")"+d+"("+2*a+d2+b+")"+d+"("+b*2+d2+a+")"+d+"("+
    171                                 a/w+d2+b+")"+d+"("+a+d2+b/w+")"+"=");
    172                                 }
    173                                 
    174                             }
    175                             }
    176 
    177                             
    178                         
    179                     }
    180                 }
    181         }
    182             
    183             
    184         }
    185             
    186         
    187         
    188     
    189     //求最大公约数构造函数
    190     public static int gcd(int x,int y){
    191            if(y == 0)
    192                 return x;
    193          else
    194                 return gcd(y,x%y);
    195     }
    196 
    197 }

    实验截图

    2

    3

    4

    5

  • 相关阅读:
    基于spring mvc的图片验证码实现
    spring mvc controller间跳转 重定向 传参
    fedora23安装配置记录
    Qt移动开发大部分的场景基本上实现没问题,listview支持刷新3000~5000的实时数据没有任何压力(QML的几个大型应用)
    经过了这么多年的发展,软件开发行业已经完全渗入了整个社会
    Qt云服务/云计算平台QTC(Qt Cloud Services)入门(0)
    Windows下用VC与QT编译MPI程序入门
    VS2008下QT整合OGRE
    表现层及ASP.NET MVC介绍(二)
    DDD分层架构的进化
  • 原文地址:https://www.cnblogs.com/gdp176119/p/5295353.html
Copyright © 2011-2022 走看看