• 二柱子代码版(应该不会在动它了)


    今天对二柱子进行了升级,可以设置参数,选择难度

      1 package random;
      2 
      3 
      4 import java.util.*;
      5 import javax.script.*;
      6 
      7 public class Quesfa {
      8 
      9     static char[] fu = {'+','-','*','/'};//符号
     10     static String[] ti = new String[100];//
     11     static String[] daan = new String[100];
     12     static String[] cuoti = new String[100];//错题
     13     static String[] cuotidaan = new String[100];//错题答案
     14     static int tishu = 30;//题数
     15     static int caozuoshu = 2;//操作数
     16     static int fanwei = 100;//范围
     17     static int cuotishu = 0;//错题数
     18 
     19     public static void choose()
     20     {
     21         Scanner s = new Scanner(System.in);
     22         
     23         System.out.println("1. 参数设置");
     24         System.out.println("2. 小学二年级口算题");
     25         System.out.println("3. 小学三年级口算题");
     26         System.out.println("4. 小学四年级口算题");
     27         System.out.println("5. 错题集");
     28         
     29         int x = s.nextInt();
     30         while(x!=0) {
     31         
     32         switch (x) {
     33         
     34         case 1:
     35             canshu();
     36             break;
     37         case 2:
     38             chuti(tishu, 2, fanwei);
     39             suandaan();
     40             zuoti();
     41             break;
     42         case 3:
     43             chuti(tishu, 4, fanwei);
     44             suandaan();
     45             zuoti();
     46             break;
     47         case 4:
     48             chuti(tishu, 5, fanwei);
     49             suandaan();
     50             zuoti();
     51             break;
     52         case 5:
     53             cuotiji();
     54             break;
     55             
     56         default:System.out.println("请输入1-5");
     57             break;
     58         }
     59         System.out.println("1. 参数设置");
     60         System.out.println("2. 小学二年级口算题");
     61         System.out.println("3. 小学三年级口算题");
     62         System.out.println("4. 小学四年级口算题");
     63         System.out.println("5. 错题集");
     64         x = s.nextInt();
     65         }
     66         
     67     }
     68     
     69     //参数
     70     public static void canshu()
     71     {
     72         Scanner c = new Scanner(System.in);
     73         System.out.print("题数:");
     74         tishu=c.nextInt();
     75         
     76         //System.out.print("操作数:");
     77         //caozuoshu=c.nextInt();
     78         
     79         System.out.print("范围:");
     80         fanwei=c.nextInt();
     81         System.out.println("参数设置完成");
     82     }
     83     
     84     //出题
     85     public static void chuti(int tishu,int caozuoshu,int fanwei)
     86     {
     87         int a=0;
     88         int c=0;
     89         int d=0;
     90         int e=0;
     91         Random r=new Random();
     92         for(int i=0;i<tishu;i++)
     93         {
     94             StringBuilder b = new StringBuilder();
     95             if(caozuoshu==2)
     96             {
     97                 d=r.nextInt(4);
     98                 if(d==3)
     99                 {
    100                     while(true)
    101                     {
    102                         e=r.nextInt(fanwei+1);
    103                         c=r.nextInt(fanwei+1);
    104                         a=c*e;
    105                         if(a<=fanwei&&c!=0)
    106                             break;
    107                     }
    108                 }
    109                 else {
    110                     a=r.nextInt(fanwei+1);
    111                     d=r.nextInt(3);
    112                     c=r.nextInt(fanwei+1);
    113                 }
    114                 b.append(a);
    115                 b.append(fu[d]);
    116                 b.append(c);
    117             }
    118             else {
    119                 for(int j=1;j<=2*caozuoshu-1;j+=2)
    120                 {
    121                     a=r.nextInt(fanwei+1);
    122                     b.append(a);
    123                     if(j!=2*caozuoshu-1) {
    124                         b.append(fu[r.nextInt(3)]);
    125                     }
    126                 }
    127             }
    128             
    129             ti[i]= b.toString();
    130         }
    131         
    132     }
    133     
    134     //查重
    135     public static boolean same()
    136     {
    137         for(int i=0;i<tishu;i++) {
    138             for(int j=i+1;j<tishu;j++) {
    139                 if(ti[i].equals(ti[j]))
    140                 {
    141                     //System.out.println("有重复");
    142                     return true;
    143                 }
    144             }
    145         }
    146         //System.out.println("无重复");
    147         return false;
    148     }
    149     
    150     //算答案
    151     public static void suandaan()
    152     {
    153         ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
    154         ScriptEngine scriptEngine = scriptEngineManager.getEngineByName("nashorn");
    155         
    156         for(int i=0;i<tishu;i++) {
    157             try {
    158                 String result = String.valueOf(scriptEngine.eval(ti[i]));
    159                 //System.out.println(result);
    160                 daan[i]=result;
    161             } catch (ScriptException e) {
    162                 e.printStackTrace();
    163             }
    164         }
    165         
    166     }
    167     
    168     
    169     //做题
    170     public static void zuoti() {
    171         Scanner indaan = new Scanner(System.in);
    172         String an="";
    173         
    174         for(int i=0;i<tishu;i++)//去重打印
    175         {
    176             if(!same()) {
    177                 System.out.print(i+1+".	"+ti[i]+"=");
    178                 an=indaan.next();
    179                 if (an.equals(daan[i])) {
    180                     System.out.println("√");
    181                 }
    182                 else {
    183                     System.out.println("×");
    184                     cuoti[cuotishu]=ti[i];
    185                     cuotidaan[cuotishu]=daan[i];
    186                     cuotishu++;
    187                 }
    188             }
    189             else {
    190                 i--;
    191             }
    192         }
    193         System.out.println("错题数:"+cuotishu+"   正确率:"+(double)(tishu-cuotishu)*100/tishu+"%");
    194     }
    195     
    196     //错题集
    197     public static void cuotiji()
    198     {
    199         Scanner indaan = new Scanner(System.in);
    200         String an="";
    201         System.out.println("错题集:");
    202         int temp=0;
    203         for(int i=0;i<cuotishu;i++)
    204         {
    205                 System.out.println(i+1+".	"+cuoti[i]+"=");
    206                 an=indaan.next();
    207                 
    208                 if (an.equals(cuotidaan[i])) {
    209                     System.out.println("√");
    210                 }
    211                 else {
    212                     System.out.println("×");
    213                     cuoti[temp]=cuoti[i];
    214                     cuotidaan[temp]=cuotidaan[i];
    215                     temp++;
    216                 }
    217         }
    218         cuotishu = temp;
    219         if(cuotishu==0)
    220             System.out.println("没错题了");
    221             
    222         }
    223     
    224     public static void main(String[] args) {
    225         choose();
    226      }
    227 
    228 }

    接下来要去学习web版了

    .......

  • 相关阅读:
    golang中使用selenium进行爬虫
    SAS关于宏、宏函数、宏变量、data步、proc步和call execute的理解
    golang基础--slice和array
    MySQL基础操作——转
    wamp的手动安装
    SQL索引一步到位
    C语言的随机发牌程序(红桃、黑桃、梅花、方块)
    mysql数据库的导入导出
    比Android更深远的改变世界——谷歌开源人工智能系统TensorFlow文档中文版
    TensorFlow博客翻译——用TensorFlow在云端进行机器学习
  • 原文地址:https://www.cnblogs.com/a8047/p/13817669.html
Copyright © 2020-2023  润新知