软件工程个人作业02

代码:

//随机运算
//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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值