zoukankan      html  css  js  c++  java
  • 软件工程——四则运算2

    一、设计思想:

         1、 为了实现题目中的要求,可以将各个功能由方法来实现,首先设计加减法运算方法。

         2、加法方法:jiaFa(int range/*数值范围*/,int negative_OK/*0表示无负数,1表示可有负数*/,int fraction/*0表示无分数,1表示真分数,2表示支持假分数*/,int decimal/*支持小数位数*/),参数的不同代表用户不同的选择和对应的功能,减法、乘法、除法和加法类似。

         3、是否带括号的功能:three_Operands()涉及3个操作数,其中前两个数是由加减乘除方法产生的,另一个再随机生成。

         4、为了实现避免题目重复的功能,可以将产生的运算题目设置为字符串类型,放到一个数组中,每产生一个题目就依次放到数组中,并和以经产生的式子比较是否相同,利用String类中的equals方法进行比较。

         5、实现打印方式,利用%判断是否换行,题目数量和每行题目数量由用户自行输入。

    二、源程序

      1 package math;
      2 import java.util.Random;
      3 import java.text.DecimalFormat;
      4 import java.util.Scanner;
      5 import java.util.*;
      6 
      7 public class arithmetic {
      8     public static void main(String args[])
      9     {    
     10         int ch;//是否继续
     11         int option,range,negative_OK,fraction,decimal,num;
     12         Scanner cin=new Scanner(System.in);
     13         do{
     14             menu0();
     15             option=cin.nextInt();
     16             switch(option)
     17             {
     18             case 1:System.out.println("您选择了的是:“加减法简单运算”!");
     19                    System.out.print("输入操作数最大值:");
     20                    range=cin.nextInt();
     21                    //System.out.println();
     22                    System.out.print("输入题目的个数:");
     23                    num=cin.nextInt();
     24                    String list[];
     25                    list=new String[num];
     26                    list[0]=jiaFa(range,0,0,0);
     27                    for(int i=1;i<num;i++)
     28                    {
     29                        int flag;
     30                        //避免题目重复
     31                        do{
     32                            flag=0;
     33                            if((int)(Math.random()*2)==1)
     34                            {
     35                                list[i]=jiaFa(range,0,0,0);
     36                            }
     37                            else
     38                            {
     39                                list[i]=jianFa(range,0,0,0);
     40                            }
     41                            for(int t=0;t<i;t++)
     42                            {
     43                                if(list[i].equals(list[t]))
     44                                    flag=1;
     45                            }
     46                        }while(flag==1);
     47                    }
     48                    System.out.print("请输入每行的题目数:");
     49                    int n=cin.nextInt();
     50                    for(int i=0;i<num;i++)
     51                    {
     52                        System.out.print(list[i]+"="+"	");
     53                        if((i+1)%n==0)
     54                            System.out.println();
     55                    }
     56                     break;
     57             case 2:
     58                    System.out.println("您选择了的是:“含乘、除法的四则运算”!");
     59                    System.out.print("输入操作数最大值:");
     60                    range=cin.nextInt();
     61                    System.out.print("输入题目的个数:");
     62                    num=cin.nextInt();
     63                    System.out.print("输入每行题目的个数:");
     64                    n=cin.nextInt();
     65                    for(int i=0;i<num;i++)
     66                    {
     67                        int flag=(int)(Math.random()*4);
     68                        if(flag==0)
     69                            System.out.print(jiaFa(range,0,0,0)+"="+"	");
     70                        else if(flag==1)
     71                            System.out.print(jianFa(range,0,0,0)+"="+"	");
     72                        else if(flag==2)
     73                            System.out.print(chuFa(range,0)+"="+"	");
     74                        else if(flag==3)
     75                            System.out.print(chengFa(range,0)+"="+"	");
     76                        if((i+1)%n==0)
     77                            System.out.println();
     78                    }
     79                    break;
     80             case 3:                   
     81                System.out.println("您选择了的是:“包括真分数的四则运算”!");
     82                System.out.print("输入操作数最大值:");
     83                range=cin.nextInt();
     84                System.out.print("输入题目的个数:");
     85                num=cin.nextInt();
     86                System.out.print("输入每行题目的个数:");
     87                n=cin.nextInt();
     88                for(int i=0;i<num;i++)
     89                {  
     90                    String str="";
     91                    int flag=(int)(Math.random()*4);
     92                    if(flag==0)
     93                    {
     94                        str=jiaFa(range,0,1,0)+"=";
     95                        System.out.print(str);
     96                    }
     97                    else if(flag==1)
     98                    {
     99                        str=jianFa(range,0,1,0)+"=";
    100                        System.out.print(str);
    101                    }
    102                    else if(flag==2)
    103                    {
    104                        str=chengFa(range,1)+"=";
    105                        System.out.print(str);
    106                    }
    107                    else if(flag==3)
    108                    {
    109                        str=chuFa(range,1)+"=";
    110                        System.out.print(str);
    111                    }
    112                    for(int k=0;k<20-str.length();k++)
    113                    {
    114                        System.out.print(" ");
    115                    }
    116                    if((i+1)%n==0)
    117                        System.out.println();
    118                }
    119                break;
    120             case 4:                   
    121                    System.out.println("您选择了的是:“包括假分数的四则运算”!");
    122                    System.out.print("输入操作数最大值:");
    123                    range=cin.nextInt();
    124                    //System.out.println();
    125                    System.out.print("输入题目的个数:");
    126                    num=cin.nextInt();
    127                    System.out.print("输入每行题目的个数:");
    128                    n=cin.nextInt();
    129                    for(int i=0;i<num;i++)
    130                    {
    131                        String str="";
    132                        int flag=(int)(Math.random()*4);
    133                        if(flag==0)
    134                        {
    135                            str=jiaFa(range,0,2,0)+"=";
    136                            System.out.print(str);
    137                        }
    138                        else if(flag==1)
    139                        {
    140                            str=jianFa(range,0,2,0)+"=";
    141                            System.out.print(str);
    142                        }
    143                        else if(flag==2)
    144                        {
    145                            str=chengFa(range,2)+"=";
    146                            System.out.print(str);
    147                        }
    148                        else if(flag==3)
    149                        {
    150                            str=chuFa(range,2)+"=";
    151                            System.out.print(str);
    152                        }
    153                        for(int k=0;k<20-str.length();k++)
    154                        {
    155                            System.out.print(" ");
    156                        }
    157                        if((i+1)%n==0)
    158                            System.out.println();
    159                    }
    160                    break;
    161             case 5:
    162                    System.out.println("您选择了的是:“包括小数的运算”!");
    163                    System.out.print("输入所要保留小数点的位数:");
    164                    int  r=cin.nextInt();
    165                   // System.out.println();
    166                    System.out.print("输入操作数最大值:");
    167                    range=cin.nextInt();
    168                    System.out.println();
    169                    System.out.print("输入题目的个数:");
    170                    num=cin.nextInt();
    171                    System.out.print("输入每行题目的个数:");
    172                    n=cin.nextInt();
    173                    for(int i=0;i<num;i++)
    174                    {
    175                        String str="";
    176                        int flag=(int)(Math.random()*4);
    177                        if(flag==0)
    178                        {
    179                            str=jiaFa(range,0,0,r)+"=";
    180                            System.out.print(str);
    181                        }
    182                        else if(flag==1)
    183                        {
    184                            str=jianFa(range,0,0,r)+"=";
    185                            System.out.print(str);
    186                        }
    187                        else if(flag==2)
    188                        {
    189                            str=chengFa(range,0)+"=";
    190                            System.out.print(str);
    191                        }
    192                        else if(flag==3)
    193                        {
    194                            str=chuFa(range,0)+"=";
    195                            System.out.print(str);
    196                        }
    197                        for(int k=0;k<20-str.length();k++)
    198                        {
    199                            System.out.print(" ");
    200                        }
    201                        if((i+1)%n==0)
    202                            System.out.println();
    203                    }
    204                    break;
    205             case 6:
    206                    System.out.println("您选择了的是:“持带括号的运算”!");
    207                    System.out.print("输入题目的个数:");
    208                    num=cin.nextInt();
    209                    System.out.print("输入每行题目的个数:");
    210                    n=cin.nextInt();
    211                    for(int i=0;i<num;i++)
    212                    {
    213                        String str="";
    214                        str=three_Operands()+"=";
    215                        System.out.print(str);
    216                        for(int k=0;k<15-str.length();k++)
    217                        {
    218                            System.out.print(" ");
    219                        }
    220                        if((i+1)%n==0)
    221                            System.out.println();
    222                    }
    223                    break;
    224             }
    225             System.out.print("是否继续(1:继续,0:退出):");
    226             ch=cin.nextInt();
    227         }while(ch==1);
    228     }
    229     
    230     public static void menu0()//主菜单函数
    231     {
    232         System.out.println("           欢迎使用自动出题器!");
    233         System.out.println();
    234         System.out.println("====================================");
    235         System.out.println("||.........1、加、减法简单运算 ..........||");
    236         System.out.println("||.........2、含乘、除法的四则运算....... ||");
    237         System.out.println("||.........3、包括真分数的四则运算........||");
    238         System.out.println("||.........4、包括假分数的四则运算....... ||");
    239         System.out.println("||.........5、包括小数的运算............||");
    240         System.out.println("||.........6、支持带括号的运算...........||");
    241         System.out.println("=====================================");
    242         System.out.println();
    243         System.out.print("~~~~~请选择您需要的功能: ");
    244     }
    245     
    246    public static String jiaFa(int range/*数值范围*/,int negative_OK/*0表示无负数,1表示可有负数*/,
    247                                         int  fraction/*0表示无分数,1表示真分数,2表示支持假分数*/,int decimal/*支持小数位数*/)//加法运算
    248    {   
    249        String str1="",str2="";
    250        int rdm1,rdm2,rdm,rdm0;
    251        if(fraction==0)//不支持分数
    252        {
    253            rdm1=((int)(Math.random()*range));
    254            rdm2=((int)(Math.random()*range));
    255            if(negative_OK==1)
    256            {
    257               if((int)(Math.random()*2)==1)
    258               {
    259                  rdm1=-rdm1;
    260               }
    261               if((int)(Math.random()*2)==1)
    262               {
    263                  rdm2=-rdm2;
    264               }
    265           }
    266           if(((int)(Math.random()*2)==1)&&(decimal>0))
    267           {
    268                double rdm00;
    269                switch(decimal)
    270                {
    271                case 1:DecimalFormat df1 = new DecimalFormat( "0.0");
    272                       rdm00=Math.random();
    273                       str1=df1.format(rdm00+rdm1);
    274                       break;
    275                case 2:DecimalFormat df2 = new DecimalFormat( "0.00");
    276                       rdm00=Math.random();
    277                       str1=df2.format(rdm00+rdm1);
    278                       break;
    279                case 3:DecimalFormat df3 = new DecimalFormat( "0.000");
    280                       rdm00=(Math.random());
    281                       str1=df3.format(rdm00+rdm1);
    282                       break;
    283                case 4:DecimalFormat df4 = new DecimalFormat( "0.0000");
    284                       rdm00=(Math.random());
    285                       str1=df4.format(rdm00+rdm1);
    286                       break;
    287                case 5:DecimalFormat df5 = new DecimalFormat( "0.00000");
    288                       rdm00=(Math.random());
    289                       str1=df5.format(rdm00+rdm1);
    290                       break;
    291                }
    292           }
    293           else
    294           {
    295               str1=""+rdm1;
    296           }
    297           if(((int)(Math.random()*2)==1)&&(decimal>0))
    298           {
    299                double rdm00;
    300                switch(decimal)
    301                {
    302                case 0:DecimalFormat df0 = new DecimalFormat( "0.");
    303                       rdm00=Math.random();
    304                       str2=df0.format(rdm00+rdm2);
    305                       break;
    306                case 1:DecimalFormat df1 = new DecimalFormat( "0.0");
    307                       rdm00=Math.random();
    308                       str2=df1.format(rdm00+rdm2);
    309                       break;
    310                case 2:DecimalFormat df2 = new DecimalFormat( "0.00");
    311                       rdm00=Math.random();
    312                       str2=df2.format(rdm00+rdm2);
    313                       break;
    314                case 3:DecimalFormat df3 = new DecimalFormat( "0.000");
    315                       rdm00=(Math.random());
    316                       str2=df3.format(rdm00+rdm2);
    317                       break;
    318                case 4:DecimalFormat df4 = new DecimalFormat( "0.0000");
    319                       rdm00=(Math.random());
    320                       str2=df4.format(rdm00+rdm2);
    321                       break;
    322                case 5:DecimalFormat df5 = new DecimalFormat( "0.00000");
    323                       rdm00=(Math.random());
    324                       str2=df5.format(rdm00+rdm2);
    325                       break;
    326                }
    327           }
    328           else
    329           {
    330               str2=""+rdm2;
    331           }
    332           if(rdm1<0)
    333           {
    334               str1="("+str1+")";
    335           }
    336           if(rdm2<0)
    337           {
    338               str2="("+str2+")";
    339           }
    340        }
    341        else if(fraction==1)//支持真分数
    342        {
    343            if((int)(Math.random()*2)==0)//rdm1为整数
    344            {
    345                rdm1=((int)(Math.random()*range));
    346                if(negative_OK==1)
    347                {
    348                   if((int)(Math.random()*2)==1)
    349                   {
    350                      rdm1=-rdm1;
    351                   }
    352               }
    353               str1=""+rdm1;
    354               if(rdm1<0)
    355               {
    356                   str1="("+rdm1+")";
    357               }
    358            }
    359            else
    360            {
    361                rdm1=((int)(Math.random()*range));
    362                rdm=((int)(Math.random()*range));
    363                str1="("+(rdm1>rdm?(""+rdm+"/"+rdm1):(""+rdm1+"/"+rdm))+")";
    364            }
    365            if((int)(Math.random()*2)==0)//rdm2为整数
    366            {
    367                rdm2=((int)(Math.random()*range));
    368                if(negative_OK==1)
    369                {
    370                   if((int)(Math.random()*2)==1)
    371                   {
    372                      rdm2=-rdm2;
    373                   }
    374               }
    375               str2=""+rdm2;
    376               if(rdm2<0)
    377               {
    378                   str2="("+rdm2+")";
    379               }
    380            }
    381            else
    382            {
    383                rdm2=((int)(Math.random()*range));
    384                rdm=((int)(Math.random()*range));
    385                str2="("+(rdm2>rdm?(""+rdm+"/"+rdm2):(""+rdm2+"/"+rdm))+")";
    386            }
    387        }
    388        else if(fraction==2)//支持假分数
    389        {
    390            if((int)(Math.random()*2)==0)//rdm1为整数
    391            {
    392                rdm1=((int)(Math.random()*range));
    393                if(negative_OK==1)
    394                {
    395                   if((int)(Math.random()*2)==1)
    396                   {
    397                      rdm1=-rdm1;
    398                   }
    399               }
    400               str1=""+rdm1;
    401               if(rdm1<0)
    402               {
    403                   str1="("+rdm1+")";
    404               }
    405            }
    406            else
    407            {
    408                rdm1=((int)(Math.random()*range));
    409                rdm=((int)(Math.random()*range));
    410                str1="("+rdm+"/"+rdm1+")";
    411            }
    412            if((int)(Math.random()*2)==0)//rdm2为整数
    413            {
    414                rdm2=((int)(Math.random()*range));
    415                if(negative_OK==1)
    416                {
    417                   if((int)(Math.random()*2)==1)
    418                   {
    419                      rdm2=-rdm2;
    420                   }
    421               }
    422               str2=""+rdm2;
    423               if(rdm2<0)
    424               {
    425                   str2="("+rdm2+")";
    426               }
    427            }
    428            else
    429            {
    430                rdm2=((int)(Math.random()*range));
    431                rdm=((int)(Math.random()*range));
    432                str2="("+rdm2+"/"+rdm+")";
    433            }
    434        }
    435        return(str1+"+"+str2);
    436    }
    437    public static String jianFa(int range/*数值范围*/,int negative_OK/*0表示无负数,1表示可有负数*/,
    438            int  fraction/*0表示无分数,1表示真分数,2表示支持假分数*/,int decimal/*支持小数位数*/)//加法运算
    439 {   
    440       String str1="",str2="";
    441       int rdm1,rdm2,rdm,rdm0;
    442       if(fraction==0)//不支持分数
    443       {
    444           rdm1=((int)(Math.random()*range));
    445           rdm2=((int)(Math.random()*range));
    446           if(negative_OK==1)
    447           {
    448               if((int)(Math.random()*2)==1)
    449               {
    450                   rdm1=-rdm1;
    451               }
    452               if((int)(Math.random()*2)==1)
    453               {
    454                   rdm2=-rdm2;
    455               }
    456           }
    457           if(((int)(Math.random()*2)==1)&&(decimal>0))
    458           {
    459               double rdm00;
    460               switch(decimal)
    461               {
    462                case 1:DecimalFormat df1 = new DecimalFormat( "0.0");
    463                     rdm00=Math.random();
    464                     str1=df1.format(rdm00+rdm1);
    465                     break;
    466                case 2:DecimalFormat df2 = new DecimalFormat( "0.00");
    467                     rdm00=Math.random();
    468                     str1=df2.format(rdm00+rdm1);
    469                     break;
    470                case 3:DecimalFormat df3 = new DecimalFormat( "0.000");
    471                     rdm00=(Math.random());
    472                     str1=df3.format(rdm00+rdm1);
    473                     break;
    474                case 4:DecimalFormat df4 = new DecimalFormat( "0.0000");
    475                     rdm00=(Math.random());
    476                     str1=df4.format(rdm00+rdm1);
    477                     break;
    478                case 5:DecimalFormat df5 = new DecimalFormat( "0.00000");
    479                     rdm00=(Math.random());
    480                     str1=df5.format(rdm00+rdm1);
    481                     break;
    482                }
    483            }
    484            else
    485            {
    486                str1=""+rdm1;
    487            }
    488            if(((int)(Math.random()*2)==1)&&(decimal>0))
    489            {
    490                double rdm00;
    491                switch(decimal)
    492                {
    493                case 0:DecimalFormat df0 = new DecimalFormat( "0.");
    494                     rdm00=Math.random();
    495                     str2=df0.format(rdm00+rdm2);
    496                     break;
    497                case 1:DecimalFormat df1 = new DecimalFormat( "0.0");
    498                     rdm00=Math.random();
    499                     str2=df1.format(rdm00+rdm2);
    500                     break;
    501                case 2:DecimalFormat df2 = new DecimalFormat( "0.00");
    502                     rdm00=Math.random();
    503                     str2=df2.format(rdm00+rdm2);
    504                     break;
    505                case 3:DecimalFormat df3 = new DecimalFormat( "0.000");
    506                     rdm00=(Math.random());
    507                     str2=df3.format(rdm00+rdm2);
    508                     break;
    509                case 4:DecimalFormat df4 = new DecimalFormat( "0.0000");
    510                     rdm00=(Math.random());
    511                     str2=df4.format(rdm00+rdm2);
    512                     break;
    513                case 5:DecimalFormat df5 = new DecimalFormat( "0.00000");
    514                     rdm00=(Math.random());
    515                     str2=df5.format(rdm00+rdm2);
    516                     break;
    517                }
    518          }
    519          else
    520          {
    521               str2=""+rdm2;
    522          }
    523          if(rdm1<0)
    524          {
    525               str1="("+str1+")";
    526          }
    527          if(rdm2<0)
    528          {
    529               str2="("+str2+")";
    530          }
    531      }
    532      else if(fraction==1)//支持真分数
    533      {
    534           if((int)(Math.random()*2)==0)//rdm1为整数
    535           {
    536                rdm1=((int)(Math.random()*range));
    537                if(negative_OK==1)
    538                {
    539                     if((int)(Math.random()*2)==1)
    540                     {
    541                            rdm1=-rdm1;
    542                     }
    543                 }
    544                 str1=""+rdm1;
    545                 if(rdm1<0)
    546                 {
    547                      str1="("+rdm1+")";
    548                 }
    549             }
    550             else
    551             {
    552                  rdm1=((int)(Math.random()*range));
    553                  rdm=((int)(Math.random()*range));
    554                  str1="("+(rdm1>rdm?(""+rdm+"/"+rdm1):(""+rdm1+"/"+rdm))+")";
    555             }
    556             if((int)(Math.random()*2)==0)//rdm2为整数
    557             {
    558                  rdm2=((int)(Math.random()*range));
    559                  if(negative_OK==1)
    560                  {
    561                       if((int)(Math.random()*2)==1)
    562                  {
    563                       rdm2=-rdm2;
    564                  }
    565              }
    566              str2=""+rdm2;
    567              if(rdm2<0)
    568              {
    569                   str2="("+rdm2+")";
    570              }
    571          }
    572          else
    573          {
    574               rdm2=((int)(Math.random()*range));
    575               rdm=((int)(Math.random()*range));
    576               str2="("+(rdm2>rdm?(""+rdm+"/"+rdm2):(""+rdm2+"/"+rdm))+")";
    577           }
    578        }
    579        else if(fraction==2)//支持假分数
    580        {
    581            if((int)(Math.random()*2)==0)//rdm1为整数
    582            {
    583                rdm1=((int)(Math.random()*range));
    584                if(negative_OK==1)
    585                {
    586                    if((int)(Math.random()*2)==1)
    587                    {
    588                         rdm1=-rdm1;
    589                    }
    590                 }
    591                 str1=""+rdm1;
    592                 if(rdm1<0)
    593                 {
    594                       str1="("+rdm1+")";
    595                  }
    596              }
    597              else
    598              {
    599                   rdm1=((int)(Math.random()*range));
    600                   rdm=((int)(Math.random()*range));
    601                   str1="("+rdm+"/"+rdm1+")";
    602               }
    603               if((int)(Math.random()*2)==0)//rdm2为整数
    604               {
    605                     rdm2=((int)(Math.random()*range));
    606                     if(negative_OK==1)
    607                     {
    608                         if((int)(Math.random()*2)==1)
    609                         {
    610                             rdm2=-rdm2;
    611                          }
    612                     }
    613                     str2=""+rdm2;
    614                     if(rdm2<0)
    615                     {
    616                          str2="("+rdm2+")";
    617                     }
    618                }
    619                else
    620                {
    621                    rdm2=((int)(Math.random()*range));
    622                    rdm=((int)(Math.random()*range));
    623                    str2="("+rdm2+"/"+rdm+")";
    624                 }
    625             }
    626             return(str1+"-"+str2);
    627        }
    628    public static String chengFa(int range,int fraction)//乘法运算
    629    {
    630        String str1="",str2="";
    631        int rdm0,rdm1,rdm2,temp;
    632        if(fraction==0)
    633        {
    634            rdm1=((int)(Math.random()*range));
    635            rdm2=((int)(Math.random()*range));
    636            str1=""+rdm1;
    637            str2=""+rdm2;
    638        }
    639        else if(fraction==1)
    640        {
    641            rdm1=((int)(Math.random()*range));
    642            rdm2=((int)(Math.random()*range));
    643            str1=""+rdm1;
    644            str2=""+rdm2;
    645            if((int)(Math.random()*2)==0)
    646            {
    647                rdm0=(int)(Math.random()*range);
    648                if(rdm0>rdm1)
    649                {
    650                    temp=rdm1;
    651                    rdm1=rdm0;
    652                    rdm0=temp;
    653                }
    654                str1="("+rdm0+"/"+rdm1+")";
    655            }
    656            if((int)(Math.random()*2)==0)
    657            {
    658                rdm0=(int)(Math.random()*range);
    659                if(rdm0>rdm2)
    660                {
    661                    temp=rdm2;
    662                    rdm2=rdm0;
    663                    rdm0=temp;
    664                }
    665                str1="("+rdm0+"/"+rdm2+")";
    666            }
    667        }
    668        else if(fraction==2)
    669        {
    670            rdm1=((int)(Math.random()*range));
    671            rdm2=((int)(Math.random()*range));
    672            str1=""+rdm1;
    673            str2=""+rdm2;
    674            if((int)(Math.random()*2)==0)
    675            {
    676                rdm0=(int)(Math.random()*range);
    677                if(rdm0<rdm1)
    678                {
    679                    temp=rdm1;
    680                    rdm1=rdm0;
    681                    rdm0=temp;
    682                }
    683                str1="("+rdm0+"/"+rdm1+")";
    684            }
    685            if((int)(Math.random()*2)==0)
    686            {
    687                rdm0=(int)(Math.random()*range);
    688                if(rdm0<rdm2)
    689                {
    690                    temp=rdm2;
    691                    rdm2=rdm0;
    692                    rdm0=temp;
    693                }
    694                str1="("+rdm0+"/"+rdm2+")";
    695            }
    696        }
    697        return (str1+"*"+str2);
    698    }
    699    public static String chuFa(int range,int fraction)//除法运算
    700    {
    701        String str1="",str2="";
    702        int rdm0,rdm1,rdm2,temp;
    703        if(fraction==0)
    704        {
    705            rdm1=((int)(Math.random()*range));
    706            rdm2=((int)(Math.random()*range));
    707            str1=""+(rdm1+1);
    708            str2=""+(rdm2+1);
    709        }
    710        else if(fraction==1)
    711        {
    712            rdm1=((int)(Math.random()*range))+1;
    713            rdm2=((int)(Math.random()*range))+1;
    714            str1=""+rdm1;
    715            str2=""+rdm2;
    716            if((int)(Math.random()*2)==0)
    717            {
    718                rdm0=(int)(Math.random()*range);
    719                if(rdm0>rdm1)
    720                {
    721                    temp=rdm1;
    722                    rdm1=rdm0;
    723                    rdm0=temp;
    724                }
    725                str1="("+rdm0+"/"+rdm1+")";
    726            }
    727            if((int)(Math.random()*2)==0)
    728            {
    729                rdm0=(int)(Math.random()*range);
    730                if(rdm0>rdm2)
    731                {
    732                    temp=rdm2;
    733                    rdm2=rdm0;
    734                    rdm0=temp;
    735                }
    736                str1="("+rdm0+"/"+rdm2+")";
    737            }
    738        }
    739        else if(fraction==2)
    740        {
    741            rdm1=((int)(Math.random()*range))+1;
    742            rdm2=((int)(Math.random()*range))+1;
    743            str1=""+rdm1;
    744            str2=""+rdm2;
    745            if((int)(Math.random()*2)==0)
    746            {
    747                rdm0=(int)(Math.random()*range);
    748                if(rdm0<rdm1)
    749                {
    750                    temp=rdm1;
    751                    rdm1=rdm0;
    752                    rdm0=temp;
    753                }
    754                str1="("+rdm0+"/"+rdm1+")";
    755            }
    756            if((int)(Math.random()*2)==0)
    757            {
    758                rdm0=(int)(Math.random()*range);
    759                if(rdm0<rdm2)
    760                {
    761                    temp=rdm2;
    762                    rdm2=rdm0;
    763                    rdm0=temp;
    764                }
    765                str1="("+rdm0+"/"+rdm2+")";
    766            }
    767        }
    768        return (str1+"/"+str2);
    769    }
    770    public static String three_Operands()//有括号
    771    {
    772        int rdm=(int)(Math.random()*4);
    773        int n=(int)(Math.random()*10)+1;
    774        switch(rdm)
    775        {
    776        case 0:return("("+jiaFa(100,0,0,0)+")*"+n);
    777        case 1:return("("+jiaFa(100,0,0,0)+")/"+n);
    778        case 2:return("("+jianFa(100,0,0,0)+")*"+n);
    779        case 3:return("("+jianFa(100,0,0,0)+")/"+n);
    780        }
    781        return "";
    782    }
    783 }

    三、运行结果

    四、PSP

    一、项目计划总结:

     

    周活动总结表

    姓名:王雪青                                          日期:2015.3.14

    日期       任务

    听课

    编写程序

    阅读课本

    准备考试

     

     

    日总计

    周日

     

     

     

     

     

     

     

    周一

     300

     

     50

     

     

     

     350

    周二

     300

     

     30

     

     

     

     330

    周三

     100

     168

     

     

     

     

     268

    周四

     200

     134

     40

     

     

     

     374

    周五

     200

     158

     20

     

     

     

     378

    周六

     

     132

     

     

     

     

     132

    周总结

     1100

     610

     140

     

     

     

     

    阶段时间和效率                                            周数(上一次周活动表的周数+1):

    不包括上一周在内的累计时间                                                                         

    总计

     

     

     

     

     

     

     

    平均

     

     

     

     

     

     

     

    最大

     

     

     

     

     

     

     

    最小

     

     

     

     

     

     

     

    以前各周的累计时间                                                                                    

    总计

     

     

     

     

     

     

     

    平均

     

     

     

     

     

     

     

    最大

     

     

     

     

     

     

     

    最小

     

     

     

     

     

     

     

    二、时间记录表:

    学生      王雪青                                                       日期          2015/3/14             

    教师        王建民                                             课程           PSP       

    日期

    开始时间

    结束时间

    中断时间

    净时间

    活动

    备注

     3.11

    14:50

     16:55

     30

     95

     写程序

     

     3.11

     21:10

     22:30

     7

     73

     写程序

     

     3.12

     19:10

     21:50

     26

     134

     写程序

     

     3.13

     15:00

     16:30

     10

     80

     写程序

     

     3.13

     20:30

     22:00

     12

     78

     写程序

     

     3.14

     15:12

     17:24

     0

     132

     

     

     

    三、缺陷记录日志:

    学生     王雪青           

    日期         2015.3.14 

    教员       王建民   

    程序号        四则运算    

    日期

    编号

    类型

    引入阶段

    排除阶段

    修复时间

    修复缺陷

     3.11

     

     

     

     

     

     

     一些常见的语法错误,如丢括号,分号等

     3.12

     

     

     

     

     

     

     输出题目总是不左对齐,最后通过设置列宽解决

     3.13

     

     

     

     

     

     

     在实现避免题目重复时:数组越界     判断字符串是否相同,原来用的==,后来改为正确的equals()方法,==比较的是地址值,而equals是比较字符串的内容

     3.14

     

     

     

     

     

     

     在实现题目重复时:新式子只和上一个比较,没有和之前的比较

    由于错误没有及时记录,忘记了出错时间和解决时间,上表中没有错误的时间记录

  • 相关阅读:
    Docker 系列(九):docker-compose
    Docker实践:部署Mysql
    Linux 查看端口占用情况
    Docker实践:部署Rabbitmq容器
    VS遇到的一些问题及解决办法(持续更新)
    vue-cli2.0引入nprogress 进度条
    ElmentUI全局禁止点击遮罩层关闭el-dialog弹窗
    mongodb基础教程
    C# Socket网络编程精华篇
    MySQL 日期计算
  • 原文地址:https://www.cnblogs.com/maximumminimum/p/4337930.html
Copyright © 2011-2022 走看看