软件工程个人作业02
发布日期:2022-02-08 18:03:17 浏览次数:47 分类:技术文章

本文共 8252 字,大约阅读时间需要 27 分钟。

代码:

//随机运算

//HanZhao 2017.3.4

import java.util.*;

public class test {

 public static void main(String[] args) {

  // TODO 自动生成的方法存根
  
  char ch='y';
  while(ch=='y'){
   System.out.println("1、是否有乘除法");
         System.out.println("2、是否有括号");
         System.out.println("3、数值范围");
         System.out.println("4、加减有无负数");
         System.out.println("5、除法有无余数");
        
         Scanner scan=new Scanner(System.in);
         int choose=scan.nextInt();
        
         switch(choose)
         {
         case 1:{
          chengchufa();
          break;
         }
        
         case 2:{
          kuohao();
          break;
         }
        
         case 3:{
          fanwei();
          break;
         }
        
         case 4:{
          fushu();
          break;
         }
        
         case 5:{
          yushu();
          break;
         }
        
         default:
          System.out.println("输入错误");
          break;
         }
  }

 }

 
 
 public static void dingzhi(){
  System.out.println("请输入定制的题数:");//定制练习量
  Scanner scan=new Scanner(System.in);
  int n=scan.nextInt();
  
  System.out.println("1、整数练习");//选择题型
  System.out.println("2、分数练习");
  System.out.println("请选择:");
  Scanner scan1=new Scanner(System.in);
  int s=scan1.nextInt();
  
  String [] x=new String[n];
  String [] y=new String[n];
  
  switch(s){
  case 1:{
   int i=0;
   boolean flag;
   while(i<n)
   {
    int a=(int)(Math.random()*100);
    
    int b=(int)(Math.random()*100);
    
    int c=(int)(Math.random()*4);
    
    x[i]=new String();
    
    if(c==0)
     x[i]=a+"+"+b+"=";
    if(c==1)
     x[i]=a+"-"+b+"=";
    if(c==2)
     x[i]=a+"*"+b+"=";
    if(c==3)
     x[i]=a+"/"+b+"=";
    
    flag=true;
    
    for(int k=0;k<i;k++)
    {
     if(x[k].equals(x[i]))
     {
      flag=false;
      break;
     }
    }
    
    if(flag)
    {
     System.out.println(x[i]);
     i++;
    }
   }
   break;
  }
  
  case 2:{
   int j=0;
   boolean flag;
   while(j<n)
   {
                int x1=(int) (Math.random()*100);
    
    int y1=(int) (Math.random()*100);
    
                int x2=(int) (Math.random()*100);
    
    int y2=(int) (Math.random()*100);
    
    int z=(int) (Math.random()*4);
    
    y[j]=new String();
    
    if(x1<y1||x2<y2)
    {
     if(z==0)
      y[j]="("+x1+"/"+y1+")+"+"("+x2+"/"+y2+")=";
     
     if(z==1)
      y[j]="("+x1+"/"+y1+")-"+"("+x2+"/"+y2+")=";
     
     if(z==2)
      y[j]="("+x1+"/"+y1+")*"+"("+x2+"/"+y2+")=";
     
     if(z==3)
      y[j]="("+x1+"/"+y1+")/"+"("+x2+"/"+y2+")=";
     
     flag=true;
     
     for(int l=0;l<j;l++)
     {
      if(y[l].equals(y[j]))
      {
       flag=false;
       break;
      }
     }
     
     if(flag)
     {
      System.out.println(y[j]);
      j++;
     }
    }
    break;
   }
  }
  }
  
 }
 public static void chengchufa(){
  System.out.println("1、有乘除法");
  System.out.println("2、无乘除法");
  Scanner choice=new Scanner(System.in);
  int xuanze=choice.nextInt();
  if(xuanze==1)
  {
   dingzhi();
  }
  
  else
  {
   System.out.println("请输入定制的题数:");//定制练习量
   Scanner scan=new Scanner(System.in);
   int n=scan.nextInt();
   
   System.out.println("1、整数练习");//选择题型
   System.out.println("2、分数练习");
   System.out.println("请选择:");
   Scanner scan1=new Scanner(System.in);
   int s=scan1.nextInt();
   
   String [] x=new String[n];
   String [] y=new String[n];
   
   switch(s){
   case 1:{
    int i=0;
    boolean flag;
    while(i<n)
    {
     int a=(int)(Math.random()*100);
     
     int b=(int)(Math.random()*100);
     
     int c=(int)(Math.random()*2);
     
     x[i]=new String();
     
     if(c==0)
      x[i]=a+"+"+b+"=";
     if(c==1)
      x[i]=a+"-"+b+"=";
     
     
     flag=true;
     
     for(int k=0;k<i;k++)
     {
      if(x[k].equals(x[i]))
      {
       flag=false;
       break;
      }
     }
     
     if(flag)
     {
      System.out.println(x[i]);
      i++;
     }
    }
    break;
   }
   
   case 2:{
    int j=0;
    boolean flag;
    
    while(j<n)
    {
                 int x1=(int) (Math.random()*100);
     
     int y1=(int) (Math.random()*100);
     
                 int x2=(int) (Math.random()*100);
     
     int y2=(int) (Math.random()*100);
     
     int z=(int) (Math.random()*2);
     
     y[j]=new String();
     
     if(x1<y1||x2<y2)
     {
      if(z==0)
       y[j]="("+x1+"/"+y1+")+"+"("+x2+"/"+y2+")=";
      
      if(z==1)
       y[j]="("+x1+"/"+y1+")-"+"("+x2+"/"+y2+")=";
      
      
      flag=true;
      
      for(int l=0;l<j;l++)
      {
       if(y[l].equals(y[j]))
       {
        flag=false;
        break;
       }
      }
      
      if(flag)
      {
       System.out.println(y[j]);
       j++;
      }
     }
     break;
    }
   }
   }

  }

 }
    public static void kuohao(){
     
    }
    public static void fanwei(){
     System.out.println("请输入定制的题数:");//定制练习量
  Scanner scan=new Scanner(System.in);
  int n=scan.nextInt();
  
  System.out.println("请输入数值范围:");//数值范围
  Scanner scan2=new Scanner(System.in);
  int t=scan2.nextInt();
  
  System.out.println("1、整数练习");//选择题型
  System.out.println("2、分数练习");
  System.out.println("请选择:");
  Scanner scan1=new Scanner(System.in);
  int s=scan1.nextInt();
  
  String [] x=new String[n];
  String [] y=new String[n];
  
  switch(s){
  case 1:{
   int i=0;
   boolean flag;
   while(i<n)
   {
    int a=(int)(Math.random()*t);
    
    int b=(int)(Math.random()*t);
    
    int c=(int)(Math.random()*4);
    
    x[i]=new String();
    
    if(c==0)
     x[i]=a+"+"+b+"=";
    if(c==1)
     x[i]=a+"-"+b+"=";
    if(c==2)
     x[i]=a+"*"+b+"=";
    else
     x[i]=a+"/"+b+"=";
    
    flag=true;
    
    for(int k=0;k<i;k++)
    {
     if(x[k].equals(x[i]))
     {
      flag=false;
      break;
     }
    }
    
    if(flag)
    {
     System.out.println(x[i]);
     i++;
    }
   }
   break;
  }
  
  case 2:{
   int j=0;
   boolean flag;
   
   while(j<n)
   {
                int x1=(int) (Math.random()*t);
    
    int y1=(int) (Math.random()*t);
    
                int x2=(int) (Math.random()*t);
    
    int y2=(int) (Math.random()*t);
    
    int z=(int) (Math.random()*4);
    
    y[j]=new String();
    
    if(x1<y1||x2<y2)
    {
     if(z==0)
      y[j]="("+x1+"/"+y1+")+"+"("+x2+"/"+y2+")=";
     
     if(z==1)
      y[j]="("+x1+"/"+y1+")-"+"("+x2+"/"+y2+")=";
     
     if(z==2)
      y[j]="("+x1+"/"+y1+")*"+"("+x2+"/"+y2+")=";
     
     if(z==3)
      y[j]="("+x1+"/"+y1+")/"+"("+x2+"/"+y2+")=";
     
     flag=true;
     
     for(int l=0;l<j;l++)
     {
      if(y[l].equals(y[j]))
      {
       flag=false;
       break;
      }
     }
     
     if(flag)
     {
      System.out.println(y[j]);
      j++;
     }
    }
    break;
   }
  }
  }
    }
    public static void fushu(){
     System.out.println("1、加减无负数");
     System.out.println("2、加减有负数");
     Scanner scann=new Scanner(System.in);
     int sca=scann.nextInt();
     switch(sca)
     {
        case 1:{
         dingzhi();
        }
       
        case 2:{
         System.out.println("请输入定制的题数:");//定制练习量
       Scanner scan=new Scanner(System.in);
       int n=scan.nextInt();
       
       System.out.println("1、整数练习");//选择题型
       System.out.println("2、分数练习");
       System.out.println("请选择:");
       Scanner scan1=new Scanner(System.in);
       int s=scan1.nextInt();
       
       String [] x=new String[n+1];
       String [] y=new String[n+1];
       
       switch(s){
       case 1:{
        int i=0;
        boolean flag;
        while(i<=n)
        {
         int a=(int)(Math.random()*100);
         
         int b=(int)(Math.random()*100);
         
         int c=(int)(Math.random()*4);
         
         int d=(int)(Math.random()*2);
         
         int e=(int)(Math.random()*2);
         
         int q=0;
         if(d==0)
          q=1;
         if(d==1)
          q=-1;
         
         int p=0;
         if(e==0)
          p=1;
         if(e==1)
          p=-1;
         
         x[i]=new String();
         
         if(c==0&&d==0&&e==0)
          x[i]=a*q+"+"+b*p+"=";
         
         if(c==0&&d==0&&e==1)
          x[i]=a*q+"+"+"("+b*p+")"+"=";
         
         if(c==0&&d==1&&e==0)
          x[i]="("+a*q+")"+"+"+b*p+"=";
         
         if(c==0&&d==1&&e==1)
          x[i]="("+a*q+")"+"+"+"("+b*p+")"+"=";
         
         if(c==0&&d==0&&e==0)
          x[i]=a*q+"-"+b*p+"=";
         
         if(c==0&&d==0&&e==1)
          x[i]=a*q+"-"+"("+b*p+")"+"=";
         
         if(c==0&&d==1&&e==0)
          x[i]="("+a*q+")"+"-"+b*p+"=";
         
         if(c==0&&d==1&&e==1)
          x[i]="("+a*q+")"+"-"+"("+b*p+")"+"=";
      
         if(c==2)
          x[i]=a+"*"+b+"=";
         
         if(c==3)
          x[i]=a+"/"+b+"=";
         
         flag=true;
         
         for(int k=0;k<i;k++)
         {
          if(x[k].equals(x[i]))
          {
           flag=false;
           break;
          }
         }
         
         if(flag)
         {
          System.out.println(x[i]);
          i++;
         }
        }
        break;
       }
       
       case 2:{
        int j=0;
        boolean flag;
        while(j<n)
        {
                     int x1=(int) (Math.random()*100);
         
         int y1=(int) (Math.random()*100);
         
                     int x2=(int) (Math.random()*100);
         
         int y2=(int) (Math.random()*100);
         
         int z=(int) (Math.random()*4);
         
         y[j]=new String();
         
         if(x1<y1||x2<y2)
         {
          if(z==0)
           y[j]="("+x1+"/"+y1+")+"+"("+x2+"/"+y2+")=";
          
          if(z==1)
           y[j]="("+x1+"/"+y1+")-"+"("+x2+"/"+y2+")=";
          
          if(z==2)
           y[j]="("+x1+"/"+y1+")*"+"("+x2+"/"+y2+")=";
          
          if(z==3)
           y[j]="("+x1+"/"+y1+")/"+"("+x2+"/"+y2+")=";
          
          flag=true;
          
          for(int l=0;l<j;l++)
          {
           if(y[l].equals(y[j]))
           {
            flag=false;
            break;
           }
          }
          
          if(flag)
          {
           System.out.println(y[j]);
           j++;
          }
         }
         break;
        }
       }
       }

        }

     }
    }
    public static void yushu(){
     System.out.println("1、除法有余数");
     System.out.println("2、除法无余数");
     Scanner scann=new Scanner(System.in);
     int sca=scann.nextInt();
     
     if(sca==1)
     {
      System.out.println("请输入定制的题数:");//定制练习量
      Scanner scan=new Scanner(System.in);
      int n=scan.nextInt();
      
      String [] x=new String[n];
      
   int i=0;
   boolean flag;
   while(i<n)
   {
    int a=(int)(Math.random()*100);
    
    int b=(int)(Math.random()*100);
    
    int c=(int)(Math.random()*4);
    
    x[i]=new String();
    
    if(c==0)
     x[i]=a+"+"+b+"=";
    if(c==1)
     x[i]=a+"-"+b+"=";
    if(c==2)
     x[i]=a+"*"+b+"=";
    if(c==3&&a%b!=0)
     x[i]=a+"/"+b+"=";
    if(c==3&&a%b==0)
     i--;
     
    flag=true;
    
    for(int k=0;k<i;k++)
    {
     if(x[k].equals(x[i]))
     {
      flag=false;
      break;
     }
    }
    
    if(flag)
    {
     System.out.println(x[i]);
     i++;
    }
   }
  
     }
     
     
     if(sca==2)
     {
      System.out.println("请输入定制的题数:");//定制练习量
      Scanner scan=new Scanner(System.in);
      int n=scan.nextInt();
      
      String [] x=new String[n];
      
   int i=0;
   boolean flag;
   while(i<n)
   {
    int a=(int)(Math.random()*100);
    
    int b=(int)(Math.random()*100);
    
    int c=(int)(Math.random()*4);
    
    x[i]=new String();
    
    if(c==0)
     x[i]=a+"+"+b+"=";
    if(c==1)
     x[i]=a+"-"+b+"=";
    if(c==2)
     x[i]=a+"*"+b+"=";
    if(c==3&&a%b==0)
     x[i]=a+"/"+b+"=";
    if(c==3&&a%b!=0)
     i--;
     
    flag=true;
    
    for(int k=0;k<i;k++)
    {
     if(x[k].equals(x[i]))
     {
      flag=false;
      break;
     }
    }
    
    if(flag)
    {
     System.out.println(x[i]);
     i++;
    }
   }
  
     }
    }

}

 

截图:

项目计划日志

         听课       阅读       编程

周一                20         100

周二        

周三

周四

周五   100       10          40       

周六

周日                             80

 

 

时间记录日志

周一           晚上  六点半到八点

周五           课上  三点二十到三点五十

周日           下午  四点到六点

 

 

缺陷日志

括号没实现

除法的无余数出了数量上的问题

 

转载于:https://www.cnblogs.com/ZHAOHAN666/p/6544773.html

转载地址:https://blog.csdn.net/dia92159/article/details/101278811 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:window.close()无效,报错Scripts may close only the windows that were opened by it的问题解决办法...
下一篇:返回一个整数数组中最大子数组的和

发表评论

最新留言

逛到本站,mark一下
[***.202.152.39]2024年04月07日 04时05分49秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章