结对编程—四则运算(JAVA)(卢泰佑、李密)

Github项目链接:https://github.com/lutys/arithmetic

一、项目简介

       项目要求实现一个自动生成小学四则运算题目的命令行程序。

       自然数:0, 1, 2, …。

  • 真分数:1/2, 1/3, 2/3, 1/4, 1’1/2, …。
  • 运算符:+, −, ×, ÷。
  • 括号:(, )。
  • 等号:=。
  • 分隔符:空格(用于四则运算符和等号前后)。
  • 算术表达式:e = n | e1 + e2 | e1 − e2 | e1 × e2 | e1 ÷ e2 | (e),

        其中e, e1和e2为表达式,n为自然数或真分数。

        四则运算题目:e = ,其中e为算术表达式。

 

二、功能需求与实现情况

(完成)1. 使用 -n 参数控制生成题目的个数,例如:Myapp.exe -n 10 ,将生成10个题目。

(完成)2. 使用 -r 参数控制题目中数值(自然数、真分数和真分数分母)的范围,例如:Myapp.exe -r 10 ,将生成10以内(不包括10)的四则运算题目。该参数可以设置为1或其他自然数。该参数必须给定,否则程序报错并给出帮助信息。

(完成)3. 生成的题目中计算过程不能产生负数,也就是说算术表达式中如果存在形如e1 − e2的子表达式,那么e1 ≥ e2

(完成)4. 生成的题目中如果存在形如e1 ÷ e2的子表达式,那么其结果应是真分数。

(完成)5. 每道题目中出现的运算符个数不超过3个。

(完成)6. 程序一次运行生成的题目不能重复,即任何两道题目不能通过有限次交换+和×左右的算术表达式变换为同一道题目,生成的题目存入执行程序的当前目录下的Exercises.txt文件,格式如下:

       1. 四则运算题目1

       2. 四则运算题目2

其中真分数在输入输出时采用如下格式,真分数五分之三表示为3/5,真分数二又八分之三表示为2’3/8。

(完成)7. 在生成题目的同时,计算出所有题目的答案,并存入执行程序的当前目录下的Answers.txt文件,格式如下:

                           1. 答案1

                           2. 答案2

(完成)8. 程序应能支持一万道题目的生成。

(完成)9. 程序支持对给定的题目文件和答案文件,判定答案中的对错并进行数量统计,输入参数如下:

Myapp.exe -e <exercisefile>.txt -a <answerfile>.txt 

统计结果输出到文件Grade.txt,格式如下:

Correct: 5 (1, 3, 5, 7, 9)

Wrong: 5 (2, 4, 6, 8, 10)

 

三、PSP

PSP2.1

Personal Software Process Stages

预估耗时(分钟)

实际耗时(分钟)

Planning

计划

 30  70

· Estimate

· 估计这个任务需要多少时间

 30  70

Development

开发

 1590 2997

· Analysis

· 需求分析 (包括学习新技术)

 100 200

· Design Spec

· 生成设计文档

 60  90

· Design Review

· 设计复审 (和同事审核设计文档)

 30  30

· Coding Standard

· 代码规范 (为目前的开发制定合适的规范)

 30  30

· Design

· 具体设计

 120  150

· Coding

· 具体编码

 1000  2021

· Code Review

· 代码复审

 50  75

· Test

· 测试(自我测试,修改代码,提交修改)

 200  401

Reporting

报告

 60 80

· Test Report

· 测试报告

 30  40

· Size Measurement

· 计算工作量

10  10

· Postmortem & Process Improvement Plan

· 事后总结, 并提出过程改进计划

 20 30

合计

   1680

3147

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

四、效能分析

在改进程序性能上,我们并没有做太多的改变,一开始对于过程中不能产生符数这点,我们想在生成表达式的时候每生成一部分就进行判断,但实现过程中发现这样反复的检查不利于运行效率。于是将过程中不能产生负数这一功能放在计算功能中,在每计算两个数之后判断。

五、设计实现过程

(包中各文件如图所示)

 

 大致分工:卢泰佑:计算表达式、文件的存取作答改错、主类编写

                  李密:生成表达式、查重、主类编写

calculate.java:计算表达式-———传入表达式,将表达式按数字(分数为一整体)与符号拆分放入数组,逐一判断每个元素按条件压入取出栈(数字栈、符号栈)计算出结果

create_only:生成唯一的表达式———如果存表达式的数组中为空,生成的表达式加入数组,否则每生成一个表达式就与之前的判断,如果相同则生成新的表达式

dupilcate_checking.java:查重———中缀表达式变成后缀表达式,构建二叉树,通过比较二叉树的左右孩子即可查重

GeneratingExpression.java:生成表达式———通过操作符的取值,来判定操作数的个数。通过蛮力法对表达式相应位置插入括号,并对表达式的规范进行判定。

readAnswer.java:读取作答文件———实例化FileInputStream,接着使用bufferreader从字符输入流中读取文本,缓冲各个字符,使用readline()方法逐一读取各行存入数组,返回数组类型

readFile.java:读取答案文件———原理同readAnswer.java

saveAnswers.java:写入答案———创建getOutputStream对象调用write()方法写入

saveExercises.java:写入题目———创建getOutputStream对象调用write()方法写入

六、代码说明

calculate.java(计算表达式)

import java.util.ArrayList;
import java.util.Stack;

public class calculate {
    static GeneratingExpression ges = new GeneratingExpression();
    main m = new main();
    public String jisuan(String ss) {
        
    String st1;
    int int1=0;
    ArrayList<String> a1=new ArrayList<String>();
    ArrayList<String> a2=new ArrayList<String>();
    String st=ss;
    String o,oo;
    String[] a=st.split("\\+|\\-|\\×|\\÷|\\(|\\)");
    String[] b=st.split("");
    String[] c;
    String tt = "";
    StringBuffer sb = new StringBuffer("");
    Stack<String> zhan_num = new Stack<String>();
    Stack<String> zhan_string = new Stack<String>();
    
        for(int i=0;i<a.length;i++) {//将所有数化为分数
        if(a[i].equals("")) {}
        else if(a[i].contains("/")) {}
        else {
            String fz = a[i];
            a[i]=fz+"/1";
        }
        if(!a[i].equals("")) {
            a1.add(a[i]);    
        }
        }
        
        for(int i1=0;i1<b.length;i1++) {
            if(b[i1].equals("+")) {b[i1]="m+m";}
            else if(b[i1].equals("-")) {b[i1]="m-m";}
            else if(b[i1].equals("×")) {b[i1]="m×m";}
            else if(b[i1].equals("÷")) {b[i1]="m÷m";}
            else if(b[i1].equals("(")) {b[i1]="m(m";}
            else if(b[i1].equals(")")) {b[i1]="m)m";}
        }
        for(int i2=0;i2<b.length;i2++) {
             sb.append(b[i2]);
        }
        String st2 = sb.toString();
        c = st2.split("m");
        for(int i3=0;i3<c.length;i3++) {
            if(!c[i3].equals("")) {
                a2.add(c[i3]);
            }
        }
        for(int i4=0;i4<a2.size();i4++) {
        String st3=a2.get(i4);
        if(st3.substring(0, 1).matches("\\d")) { //contains不能使用正则表达式
            a2.set(i4, a1.get(int1));
            int1++;
        }
        }
        for(int idai=0;idai<a2.size();idai++) {  //处理带分数
            if(a2.get(idai).contains("'")) {
                String dai = a2.get(idai);
                int aa = Integer.parseInt(dai.substring(0, dai.indexOf("'")));
                int bb = Integer.parseInt(dai.substring(dai.indexOf("'")+1, dai.indexOf("/")));
                String cc = dai.substring(dai.indexOf("/")+1, dai.length()); //包含起始字符
                String dd = String.valueOf(aa*bb);
                String ee = dd+"/"+cc;
                a2.set(idai, ee);
            }
        }    

        for(int i4=0;i4<a2.size();i4++) {
            String st4 = a2.get(i4);
            if(st4.substring(0, 1).matches("\\d")) {
                zhan_num.push(st4);
            }
            else if(st4.equals("(")) {
                zhan_string.push(st4);
            }
            else if(st4.equals(")")) {
                String st5 = yunsuan(zhan_num.pop(), zhan_num.pop(), zhan_string.pop());
                zhan_num.push(st5);
                zhan_string.pop();
            }
            else if(youxianji(st4)>0) {
                if (zhan_string.isEmpty()) { // 栈为空直接入栈
                    zhan_string.push(st4);
                }
                else {
                    // 如果栈顶元素优先级大于或等于要入栈的元素,将栈顶元素弹出并计算,然后入栈
                    if (youxianji(zhan_string.peek())>=youxianji(st4)) {
                        String st5 = yunsuan(zhan_num.pop(), zhan_num.pop(), zhan_string.pop());
                        //
                        String[] pp = st5.split("/");
                        if((Integer.parseInt(pp[0])<0)||(Integer.parseInt(pp[1])<0)){
                            jisuan(ges.GeneratingExpression(Integer.parseInt(m.sz1[2])));
                        }
                        zhan_num.push(st5);
                    }
                    zhan_string.push(st4);
                }
            }
            
        }
        while (!zhan_string.isEmpty()) {
            String st5 = yunsuan(zhan_num.pop(), zhan_num.pop(), zhan_string.pop());
            String[] pp = st5.split("/");
            if((Integer.parseInt(pp[0])<0)||(Integer.parseInt(pp[1])<0)){
                jisuan(ges.GeneratingExpression(Integer.parseInt(m.sz1[2])));
            }
            tt = st5;
            zhan_num.push(st5);
        }
        String[] ttt = tt.split("/");  //如为xx/1的形式,输出xx
        if(ttt[1].equals("1")) {
            return ttt[0];
        }
        else if(Integer.parseInt(ttt[0])==0) {
            return "0";
        }
        else if(Integer.parseInt(ttt[0])>Integer.parseInt(ttt[1])) {  //若分子大于分母,输出带分数
            String xx = String.valueOf(Integer.parseInt(ttt[0])/Integer.parseInt(ttt[1]));
            String yy = String.valueOf(Integer.parseInt(ttt[0])%Integer.parseInt(ttt[1]));
            String zz = xx+"'"+yy+"/"+ttt[1];
            return zz;
        }
        else {return zhan_num.pop();}
    }
            
    public static String yunsuan(String st6,String st7,String st8) { //注意两数顺序
        String[] fenshu1 = st7.split("/");
        int fenzi1 = Integer.parseInt(fenshu1[0]);
        int fenmu1 = Integer.parseInt(fenshu1[1]);
        
        String[] fenshu2 = st6.split("/");
        int fenzi2 = Integer.parseInt(fenshu2[0]);
        int fenmu2 = Integer.parseInt(fenshu2[1]);
        
        if(st8.equals("+")) {
            int fenmu3 = least_common(fenmu1,fenmu2);
            int fenzi3 = fenmu3/fenmu1*fenzi1+fenmu3/fenmu2*fenzi2;
            String s = huajian(fenmu3,fenzi3);
            return s;
        }
        else if(st8.equals("-")) {
            int fenmu3 = least_common(fenmu1,fenmu2);
            int fenzi3 = fenmu3/fenmu1*fenzi1-fenmu3/fenmu2*fenzi2;
            String s = huajian(fenmu3,fenzi3);
            return s;
        }
        else if(st8.equals("×")) {
            int fenmu3 = fenmu1*fenmu2;
            int fenzi3 = fenzi1*fenzi2;
            String s = huajian(fenmu3,fenzi3);
            return s;
        }
        else {  //除法
            int fenmu3 = fenmu1*fenzi2;
            int fenzi3 = fenzi1*fenmu2;
            String s = huajian(fenmu3,fenzi3);
            return s;
        }
    }
    public static int least_common(int int2,int int3) {  //求最小公倍数
        int y = 0;
        if(int2<int3){
        int t=int2;
        int2=int3;
        int3=t;
        }
        for(int i=int3;i<=int2*int3;i++){
        if(i%int2==0 && i%int3==0) y=i;
        }
        return y;
        }
    
    public static String huajian(int int5,int int6) {  //化简分数,int5为分母,int6为分子
        int greatest_common = greatest_common(int5,int6);
        String st8 = String.valueOf(int6/greatest_common)+"/"+String.valueOf(int5/greatest_common);
        return st8;
        }
    
    public static int greatest_common(int x, int y){  //辗转相除法求最大公约数
        if(y == 0)
        return x;
        else
        return greatest_common(y,x%y);
        }
    
    public static int youxianji(String st9) {
        if(st9.equals("+")) return 1;
        else if(st9.equals("-")) return 1;
        else if(st9.equals("×")) return 2;
        else if(st9.equals("÷")) return 2;
        else return 0;
    }
}

 GeneratingExpression.java(生成表达式)

import java.util.Random;

public class GeneratingExpression {
    
    calculate result=new calculate();
    
    String operationCharacter[]= {"+","-","×","÷"};
    int operand[]= {2,3,4};
    
    GeneratingExpression(){
        
    }
    
    public String GeneratingExpression(int k){
        int i,j,q,w,e,r;
        j=new Random().nextInt(3)+2;//设定操作数个数
        q=new Random().nextInt(k);
        w=new Random().nextInt(k-1)+1;
        e=new Random().nextInt(k);
        r=new Random().nextInt(k-1)+1;
        
        while(q/w>=k) {
            q=new Random().nextInt(k);
        }
        
        String a,b;
        String s1=huajian(w,q);
        String s2=huajian(r,e);
        String []s11=s1.split("\\/");
        String []s22=s2.split("\\/");
        q=Integer.valueOf(s11[0]);
        w=Integer.valueOf(s11[1]);
        e=Integer.valueOf(s22[0]);
        r=Integer.valueOf(s22[1]);
        
        if(q==0)a=String.valueOf(q);
        else if(q/w==0)a=q+"/"+w;
        else if(q/w<(float)q/w)a=q/w+"'"+(q-q/w*w)+"/"+w;
        else a=String.valueOf(q/w);
        if(e==0)b=String.valueOf(e);
        else if(e/r==0)b=e+"/"+r;
        else if(e/r<(float)e/r)b=e/r+"'"+(e-e/r*r)+"/"+r;
        else b=String.valueOf(e/r);
        
        if(j==2) {//两个操作数
            String op1=operationCharacter[new Random().nextInt(4)];
            String s;
            while(b.equals("0")&&op1.equals("÷")||e/r>=k) {//判0操作
                e=new Random().nextInt(k);
                r=new Random().nextInt(k-1)+1;
                s2=huajian(r,e);
                s22=s2.split("\\/");
                e=Integer.valueOf(s22[0]);
                r=Integer.valueOf(s22[1]);
                if(e==0)b=String.valueOf(e);
                else if(e/r==0)b=e+"/"+r;
                else if(e/r<(float)e/r)b=e/r+"'"+(e-e/r*r)+"/"+r;
                else b=String.valueOf(e/r);
            }
            s=a+op1+b;
            return s;
        }
        if(j==3) {//三个操作数
            int t,y;
            String c;
            String op1=operationCharacter[new Random().nextInt(4)];
            String op2=operationCharacter[new Random().nextInt(4)];
            t=new Random().nextInt(k);
            y=new Random().nextInt(k-1)+1;
            
            String s3=huajian(y,t);
            String []s33=s3.split("\\/");
            t=Integer.valueOf(s33[0]);
            y=Integer.valueOf(s33[1]);
            if(t==0)c=String.valueOf(t);
            else if(t/y==0)c=t+"/"+y;
            else if(t/y<(float)t/y)c=t/y+"'"+(t-t/y*y)+"/"+y;
            else c=String.valueOf(t/y);
            String s=null;
            i=new Random().nextInt(3);
            switch(i) {////判0操作
            case 0:{
                while(b.equals("0")&&op1.equals("÷")||e/r>=k) {
                    e=new Random().nextInt(k);
                    r=new Random().nextInt(k-1)+1;
                    s2=huajian(r,e);
                    s22=s2.split("\\/");
                    e=Integer.valueOf(s22[0]);
                    r=Integer.valueOf(s22[1]);
                    if(e==0)b=String.valueOf(e);
                    else if(e/r==0)b=e+"/"+r;
                    else if(e/r<(float)e/r)b=e/r+"'"+(e-e/r*r)+"/"+r;
                    else b=String.valueOf(e/r);
                }
                while(c.equals("0")&&op2.equals("÷")||t/y>=k) {
                    t=new Random().nextInt(k);
                    y=new Random().nextInt(k-1)+1;
                    s3=huajian(y,t);
                    s33=s3.split("\\/");
                    t=Integer.valueOf(s33[0]);
                    y=Integer.valueOf(s33[1]);
                    if(t==0)c=String.valueOf(t);
                    else if(t/y==0)c=t+"/"+y;
                    else if(t/y<(float)t/y)c=t/y+"'"+(t-t/y*y)+"/"+y;
                    else c=String.valueOf(t/y);
                }
                s=a+op1+b+op2+c;break;
            }
            case 1:{
                while(op2.equals("÷")&&c.equals("0")||t/y>=k) {
                    t=new Random().nextInt(k);
                    y=new Random().nextInt(k-1)+1;
                    s3=huajian(y,t);
                    s33=s3.split("\\/");
                    t=Integer.valueOf(s33[0]);
                    y=Integer.valueOf(s33[1]);
                    if(t==0)c=String.valueOf(t);
                    else if(t/y==0)c=t+"/"+y;
                    else if(t/y<(float)t/y)c=t/y+"'"+(t-t/y*y)+"/"+y;
                    else c=String.valueOf(t/y);
                }
                while(op1.equals("÷")&&result.jisuan(b+op2+c).equals("0")||e/r>=k||t/y>=k) {
                    e=new Random().nextInt(k);
                    r=new Random().nextInt(k-1)+1;
                    s2=huajian(r,e);
                    s22=s2.split("\\/");
                    e=Integer.valueOf(s22[0]);
                    r=Integer.valueOf(s22[1]);
                    if(e==0)b=String.valueOf(e);
                    else if(e/r==0)b=e+"/"+r;
                    else if(e/r<(float)e/r)b=e/r+"'"+(e-e/r*r)+"/"+r;
                    else b=String.valueOf(e/r);
                    t=new Random().nextInt(k);
                    y=new Random().nextInt(k-1)+1;
                    s3=huajian(y,t);
                    s33=s3.split("\\/");
                    t=Integer.valueOf(s33[0]);
                    y=Integer.valueOf(s33[1]);
                    if(t==0)c=String.valueOf(t);
                    else if(t/y==0)c=t+"/"+y;
                    else if(t/y<(float)t/y)c=t/y+"'"+(t-t/y*y)+"/"+y;
                    else c=String.valueOf(t/y);
                    while(op2.equals("÷")&&c.equals("0")||t/y>=k) {
                        t=new Random().nextInt(k);
                        y=new Random().nextInt(k-1)+1;
                        s3=huajian(y,t);
                        s33=s3.split("\\/");
                        t=Integer.valueOf(s33[0]);
                        y=Integer.valueOf(s33[1]);
                        if(t==0)c=String.valueOf(t);
                        else if(t/y==0)c=t+"/"+y;
                        else if(t/y<(float)t/y)c=t/y+"'"+(t-t/y*y)+"/"+y;
                        else c=String.valueOf(t/y);
                }
                s=a+op1+"("+b+op2+c+")";break;
            }
            }
            case 2:{
                op1=operationCharacter[new Random().nextInt(4)];
                op2=operationCharacter[new Random().nextInt(4)];
                while(op1.equals("÷")&&b.equals("0")||e/r>=k) {
                    e=new Random().nextInt(k);
                    r=new Random().nextInt(k-1)+1;
                    s2=huajian(r,e);
                    s22=s2.split("\\/");
                    e=Integer.valueOf(s22[0]);
                    r=Integer.valueOf(s22[1]);
                    if(e==0)b=String.valueOf(e);
                    else if(e/r==0)b=e+"/"+r;
                    else if(e/r<(float)e/r)b=e/r+"'"+(e-e/r*r)+"/"+r;
                    else b=String.valueOf(e/r);
                }
                while(op2.equals("÷")&&c.equals("0")||t/y>=k) {
                    t=new Random().nextInt(k);
                    y=new Random().nextInt(k-1)+1;
                    s3=huajian(y,t);
                    s33=s3.split("\\/");
                    t=Integer.valueOf(s33[0]);
                    y=Integer.valueOf(s33[1]);
                    if(t==0)c=String.valueOf(t);
                    else if(t/y==0)c=t+"/"+y;
                    else if(t/y<(float)t/y)c=t/y+"'"+(t-t/y*y)+"/"+y;
                    else c=String.valueOf(t/y);
                }
                if(op1.equals("×")||op1.equals("÷")||op2.equals("-")
                        ||op2.equals("+"))s=a+op1+b+op2+c;
                else s="("+a+op1+b+")"+op2+c;break;
            }
            }
            return s;
        }
        if(j==4) {//四个操作数
            int t,y,m,n;
            String c,d;
            String op1=operationCharacter[new Random().nextInt(4)];
            String op2=operationCharacter[new Random().nextInt(4)];
            String op3=operationCharacter[new Random().nextInt(4)];
            t=new Random().nextInt(k);
            y=new Random().nextInt(k-1)+1;
            m=new Random().nextInt(k);
            n=new Random().nextInt(k-1)+1;
            String s3=huajian(y,t);
            String s4=huajian(n,m);
            String []s33=s3.split("\\/");
            String []s44=s4.split("\\/");
            t=Integer.valueOf(s33[0]);
            y=Integer.valueOf(s33[1]);
            m=Integer.valueOf(s44[0]);
            n=Integer.valueOf(s44[1]);
            if(t==0)c="0";
            else if(t/y==0)c=t+"/"+y;
            else if(t/y<(float)t/y)c=t/y+"'"+(t-t/y*y)+"/"+y;
            else c=String.valueOf(t/y);
            if(m==0)d="0";
            else if(m/n==0)d=m+"/"+n;
            else if(m/n<(float)m/n)d=m/n+"'"+(m-m/n*n)+"/"+n;
            else d=String.valueOf(m/n);
            String s=null;
            i=new Random().nextInt(6);
            switch(i) {//判0操作
            case 0:{
                while(op1.equals("÷")&&op3.equals("÷")&&op3.equals("÷")
                        &&b.equals("0")||c.equals("0")||d.equals("0")||e/r>=k||t/y>=k||m/n>=k) {
                    if(b.equals("0")||e/r>=k) {
                        e=new Random().nextInt(k);
                        r=new Random().nextInt(k-1)+1;
                        s2=huajian(r,e);
                        s22=s2.split("\\/");
                        e=Integer.valueOf(s22[0]);
                        r=Integer.valueOf(s22[1]);
                        if(e==0)b=String.valueOf(e);
                        else if(e/r==0)b=e+"/"+r;
                        else if(e/r<(float)e/r)b=e/r+"'"+(e-e/r*r)+"/"+r;
                        else b=String.valueOf(e/r);
                    }
                    if(c.equals("0")||t/y>=k) {
                        t=new Random().nextInt(k);
                        y=new Random().nextInt(k-1)+1;
                        s3=huajian(y,t);
                        s33=s3.split("\\/");
                        t=Integer.valueOf(s33[0]);
                        y=Integer.valueOf(s33[1]);
                        if(t==0)c=String.valueOf(t);
                        else if(t/y==0)c=t+"/"+y;
                        else if(t/y<(float)t/y)c=t/y+"'"+(t-t/y*y)+"/"+y;
                        else c=String.valueOf(t/y);
                    }
                    if(d.equals("0")||m/n>=k) {
                        m=new Random().nextInt(k);
                        n=new Random().nextInt(k-1)+1;
                        s3=huajian(n,m);
                        s33=s3.split("\\/");
                        m=Integer.valueOf(s33[0]);
                        n=Integer.valueOf(s33[1]);
                        if(m==0)d=String.valueOf(m);
                        else if(m/n==0)d=m+"/"+n;
                        else if(m/n<(float)m/n)d=m/n+"'"+(m-m/n*n)+"/"+n;
                        else c=String.valueOf(m/n);
                    }
                }
                while(op1.equals("÷")&&!op2.equals("÷")&&op3.equals("÷")
                        &&b.equals("0")||d.equals("0")||e/r>=k||m/n>=k) {
                    if(b.equals("0")||e/r>=k) {
                        e=new Random().nextInt(k);
                        r=new Random().nextInt(k-1)+1;
                        s2=huajian(r,e);
                        s22=s2.split("\\/");
                        e=Integer.valueOf(s22[0]);
                        r=Integer.valueOf(s22[1]);
                        if(e==0)b=String.valueOf(e);
                        else if(e/r==0)b=e+"/"+r;
                        else if(e/r<(float)e/r)b=e/r+"'"+(e-e/r*r)+"/"+r;
                        else b=String.valueOf(e/r);
                    }
                    if(d.equals("0")||m/n>=k) {
                        m=new Random().nextInt(k);
                        n=new Random().nextInt(k-1)+1;
                        s3=huajian(n,m);
                        s33=s3.split("\\/");
                        m=Integer.valueOf(s33[0]);
                        n=Integer.valueOf(s33[1]);
                        if(m==0)d=String.valueOf(m);
                        else if(m/n==0)d=m+"/"+n;
                        else if(m/n<(float)m/n)d=m/n+"'"+(m-m/n*n)+"/"+n;
                        else c=String.valueOf(m/n);
                    }
                }
                while(op1.equals("÷")&&!op2.equals("÷")&&!op3.equals("÷")
                        &&b.equals("0")||e/r>=k) {
                    if(b.equals("0")||e/r>=k) {
                        e=new Random().nextInt(k);
                        r=new Random().nextInt(k-1)+1;
                        s2=huajian(r,e);
                        s22=s2.split("\\/");
                        e=Integer.valueOf(s22[0]);
                        r=Integer.valueOf(s22[1]);
                        if(e==0)b=String.valueOf(e);
                        else if(e/r==0)b=e+"/"+r;
                        else if(e/r<(float)e/r)b=e/r+"'"+(e-e/r*r)+"/"+r;
                        else b=String.valueOf(e/r);
                    }
                }
                    while(!op1.equals("÷")&&op2.equals("÷")&&!op3.equals("÷")
                            &&c.equals("0")||t/y>=k) {
                        if(c.equals("0")||t/y>=k) {
                            t=new Random().nextInt(k);
                            y=new Random().nextInt(k-1)+1;
                            s3=huajian(y,t);
                            s33=s3.split("\\/");
                            t=Integer.valueOf(s33[0]);
                            y=Integer.valueOf(s33[1]);
                            if(t==0)c=String.valueOf(t);
                            else if(t/y==0)c=t+"/"+y;
                            else if(t/y<(float)t/y)c=t/y+"'"+(t-t/y*y)+"/"+y;
                            else c=String.valueOf(t/y);
                        }
                    }
                    while(!op1.equals("÷")&&op2.equals("÷")&&op3.equals("÷")
                            &&c.equals("0")||d.equals("0")||t/y>=k||m/n>=k) {
                        if(c.equals("0")||t/y>=k) {
                            t=new Random().nextInt(k);
                            y=new Random().nextInt(k-1)+1;
                            s3=huajian(y,t);
                            s33=s3.split("\\/");
                            t=Integer.valueOf(s33[0]);
                            y=Integer.valueOf(s33[1]);
                            if(t==0)c=String.valueOf(t);
                            else if(t/y==0)c=t+"/"+y;
                            else if(t/y<(float)t/y)c=t/y+"'"+(t-t/y*y)+"/"+y;
                            else c=String.valueOf(t/y);
                        }
                        if(d.equals("0")||m/n>=k) {
                            m=new Random().nextInt(k);
                            n=new Random().nextInt(k-1)+1;
                            s3=huajian(n,m);
                            s33=s3.split("\\/");
                            m=Integer.valueOf(s33[0]);
                            n=Integer.valueOf(s33[1]);
                            if(m==0)d=String.valueOf(m);
                            else if(m/n==0)d=m+"/"+n;
                            else if(m/n<(float)m/n)d=m/n+"'"+(m-m/n*n)+"/"+n;
                            else c=String.valueOf(m/n);
                        }
                    }
                    while(!op1.equals("÷")&&op2.equals("÷")&&op3.equals("÷")
                            &&d.equals("0")||m/n>=k) {
                        if(d.equals("0")||m/n>=k) {
                            m=new Random().nextInt(k);
                            n=new Random().nextInt(k-1)+1;
                            s3=huajian(n,m);
                            s33=s3.split("\\/");
                            m=Integer.valueOf(s33[0]);
                            n=Integer.valueOf(s33[1]);
                            if(m==0)d=String.valueOf(m);
                            else if(m/n==0)d=m+"/"+n;
                            else if(m/n<(float)m/n)d=m/n+"'"+(m-m/n*n)+"/"+n;
                            else c=String.valueOf(m/n);
                        }
                    }
                    while(op1.equals("÷")&&op2.equals("÷")&&!op3.equals("÷")
                            &&b.equals("0")||c.equals("0")||e/r>=k||t/y>=k) {
                        if(b.equals("0")||e/r>=k) {
                            e=new Random().nextInt(k);
                            r=new Random().nextInt(k-1)+1;
                            s2=huajian(r,e);
                            s22=s2.split("\\/");
                            e=Integer.valueOf(s22[0]);
                            r=Integer.valueOf(s22[1]);
                            if(e==0)b=String.valueOf(e);
                            else if(e/r==0)b=e+"/"+r;
                            else if(e/r<(float)e/r)b=e/r+"'"+(e-e/r*r)+"/"+r;
                            else b=String.valueOf(e/r);
                        }
                        if(c.equals("0")||t/y>=k) {
                            t=new Random().nextInt(k);
                            y=new Random().nextInt(k-1)+1;
                            s3=huajian(y,t);
                            s33=s3.split("\\/");
                            t=Integer.valueOf(s33[0]);
                            y=Integer.valueOf(s33[1]);
                            if(t==0)c=String.valueOf(t);
                            else if(t/y==0)c=t+"/"+y;
                            else if(t/y<(float)t/y)c=t/y+"'"+(t-t/y*y)+"/"+y;
                            else c=String.valueOf(t/y);
                        }
                    }
                    s=a+op1+b+op2+c+op3+d;
                    break;
                }
            case 1:{
                while(op1.equals("÷")&&op3.equals("÷")&&op3.equals("÷")
                        &&b.equals("0")||c.equals("0")||d.equals("0")||e/r>=k||t/y>=k||m/n>=k) {
                    if(b.equals("0")||e/r>=k) {
                        e=new Random().nextInt(k);
                        r=new Random().nextInt(k-1)+1;
                        s2=huajian(r,e);
                        s22=s2.split("\\/");
                        e=Integer.valueOf(s22[0]);
                        r=Integer.valueOf(s22[1]);
                        if(e==0)b=String.valueOf(e);
                        else if(e/r==0)b=e+"/"+r;
                        else if(e/r<(float)e/r)b=e/r+"'"+(e-e/r*r)+"/"+r;
                        else b=String.valueOf(e/r);
                    }
                    if(c.equals("0")||t/y>=k) {
                        t=new Random().nextInt(k);
                        y=new Random().nextInt(k-1)+1;
                        s3=huajian(y,t);
                        s33=s3.split("\\/");
                        t=Integer.valueOf(s33[0]);
                        y=Integer.valueOf(s33[1]);
                        if(t==0)c=String.valueOf(t);
                        else if(t/y==0)c=t+"/"+y;
                        else if(t/y<(float)t/y)c=t/y+"'"+(t-t/y*y)+"/"+y;
                        else c=String.valueOf(t/y);
                    }
                    if(d.equals("0")||m/n>=k) {
                        m=new Random().nextInt(k);
                        n=new Random().nextInt(k-1)+1;
                        s3=huajian(n,m);
                        s33=s3.split("\\/");
                        m=Integer.valueOf(s33[0]);
                        n=Integer.valueOf(s33[1]);
                        if(m==0)d=String.valueOf(m);
                        else if(m/n==0)d=m+"/"+n;
                        else if(m/n<(float)m/n)d=m/n+"'"+(m-m/n*n)+"/"+n;
                        else c=String.valueOf(m/n);
                    }
                }
                while(op1.equals("÷")&&!op2.equals("÷")&&op3.equals("÷")
                        &&b.equals("0")||d.equals("0")||e/r>=k||m/n>=k) {
                    if(b.equals("0")||e/r>=k) {
                        e=new Random().nextInt(k);
                        r=new Random().nextInt(k-1)+1;
                        s2=huajian(r,e);
                        s22=s2.split("\\/");
                        e=Integer.valueOf(s22[0]);
                        r=Integer.valueOf(s22[1]);
                        if(e==0)b=String.valueOf(e);
                        else if(e/r==0)b=e+"/"+r;
                        else if(e/r<(float)e/r)b=e/r+"'"+(e-e/r*r)+"/"+r;
                        else b=String.valueOf(e/r);
                    }
                    if(d.equals("0")||m/n>=k) {
                        m=new Random().nextInt(k);
                        n=new Random().nextInt(k-1)+1;
                        s3=huajian(n,m);
                        s33=s3.split("\\/");
                        m=Integer.valueOf(s33[0]);
                        n=Integer.valueOf(s33[1]);
                        if(m==0)d=String.valueOf(m);
                        else if(m/n==0)d=m+"/"+n;
                        else if(m/n<(float)m/n)d=m/n+"'"+(m-m/n*n)+"/"+n;
                        else c=String.valueOf(m/n);
                    }
                }
                while(op1.equals("÷")&&!op2.equals("÷")&&!op3.equals("÷")
                        &&b.equals("0")||e/r>=k) {
                    if(b.equals("0")||e/r>=k) {
                        e=new Random().nextInt(k);
                        r=new Random().nextInt(k-1)+1;
                        s2=huajian(r,e);
                        s22=s2.split("\\/");
                        e=Integer.valueOf(s22[0]);
                        r=Integer.valueOf(s22[1]);
                        if(e==0)b=String.valueOf(e);
                        else if(e/r==0)b=e+"/"+r;
                        else if(e/r<(float)e/r)b=e/r+"'"+(e-e/r*r)+"/"+r;
                        else b=String.valueOf(e/r);
                    }
                }
                    while(!op1.equals("÷")&&op2.equals("÷")&&!op3.equals("÷")
                            &&c.equals("0")||t/y>=k) {
                        if(c.equals("0")||t/y>=k) {
                            t=new Random().nextInt(k);
                            y=new Random().nextInt(k-1)+1;
                            s3=huajian(y,t);
                            s33=s3.split("\\/");
                            t=Integer.valueOf(s33[0]);
                            y=Integer.valueOf(s33[1]);
                            if(t==0)c=String.valueOf(t);
                            else if(t/y==0)c=t+"/"+y;
                            else if(t/y<(float)t/y)c=t/y+"'"+(t-t/y*y)+"/"+y;
                            else c=String.valueOf(t/y);
                        }
                    }
                    while(!op1.equals("÷")&&op2.equals("÷")&&op3.equals("÷")
                            &&c.equals("0")||d.equals("0")||t/y>=k||m/n>=k) {
                        if(c.equals("0")||t/y>=k) {
                            t=new Random().nextInt(k);
                            y=new Random().nextInt(k-1)+1;
                            s3=huajian(y,t);
                            s33=s3.split("\\/");
                            t=Integer.valueOf(s33[0]);
                            y=Integer.valueOf(s33[1]);
                            if(t==0)c=String.valueOf(t);
                            else if(t/y==0)c=t+"/"+y;
                            else if(t/y<(float)t/y)c=t/y+"'"+(t-t/y*y)+"/"+y;
                            else c=String.valueOf(t/y);
                        }
                        if(d.equals("0")||m/n>=k) {
                            m=new Random().nextInt(k);
                            n=new Random().nextInt(k-1)+1;
                            s3=huajian(n,m);
                            s33=s3.split("\\/");
                            m=Integer.valueOf(s33[0]);
                            n=Integer.valueOf(s33[1]);
                            if(m==0)d=String.valueOf(m);
                            else if(m/n==0)d=m+"/"+n;
                            else if(m/n<(float)m/n)d=m/n+"'"+(m-m/n*n)+"/"+n;
                            else c=String.valueOf(m/n);
                        }
                    }
                    while(!op1.equals("÷")&&op2.equals("÷")&&op3.equals("÷")
                            &&d.equals("0")||m/n>=k) {
                        if(d.equals("0")||m/n>=k) {
                            m=new Random().nextInt(k);
                            n=new Random().nextInt(k-1)+1;
                            s3=huajian(n,m);
                            s33=s3.split("\\/");
                            m=Integer.valueOf(s33[0]);
                            n=Integer.valueOf(s33[1]);
                            if(m==0)d=String.valueOf(m);
                            else if(m/n==0)d=m+"/"+n;
                            else if(m/n<(float)m/n)d=m/n+"'"+(m-m/n*n)+"/"+n;
                            else c=String.valueOf(m/n);
                        }
                    }
                    while(op1.equals("÷")&&op2.equals("÷")&&!op3.equals("÷")
                            &&b.equals("0")||c.equals("0")||e/r>=k||t/y>=k) {
                        if(b.equals("0")||e/r>=k) {
                            e=new Random().nextInt(k);
                            r=new Random().nextInt(k-1)+1;
                            s2=huajian(r,e);
                            s22=s2.split("\\/");
                            e=Integer.valueOf(s22[0]);
                            r=Integer.valueOf(s22[1]);
                            if(e==0)b=String.valueOf(e);
                            else if(e/r==0)b=e+"/"+r;
                            else if(e/r<(float)e/r)b=e/r+"'"+(e-e/r*r)+"/"+r;
                            else b=String.valueOf(e/r);
                        }
                        if(c.equals("0")||t/y>=k) {
                            t=new Random().nextInt(k);
                            y=new Random().nextInt(k-1)+1;
                            s3=huajian(y,t);
                            s33=s3.split("\\/");
                            t=Integer.valueOf(s33[0]);
                            y=Integer.valueOf(s33[1]);
                            if(t==0)c=String.valueOf(t);
                            else if(t/y==0)c=t+"/"+y;
                            else if(t/y<(float)t/y)c=t/y+"'"+(t-t/y*y)+"/"+y;
                            else c=String.valueOf(t/y);
                        }
                    }
                if(op1.equals("×")||op1.equals("÷")&&op2.equals("×")||op2.equals("÷"))
                    s=a+op1+b+op2+c+op3+d;
                else if(op3.equals("÷")||op3.equals("×"))s="("+a+op1+b+op2+c+")"+op3+d;
                else s=a+op1+b+op2+c+op3+d;
                break;
            }
            case 2:{
                while(op1.equals("÷")&&op3.equals("÷")&&op3.equals("÷")
                        &&b.equals("0")||c.equals("0")||d.equals("0")||e/r>=k||m/n>=k||t/y>=k) {
                    if(b.equals("0")||e/r>=k) {
                        e=new Random().nextInt(k);
                        r=new Random().nextInt(k-1)+1;
                        s2=huajian(r,e);
                        s22=s2.split("\\/");
                        e=Integer.valueOf(s22[0]);
                        r=Integer.valueOf(s22[1]);
                        if(e==0)b=String.valueOf(e);
                        else if(e/r==0)b=e+"/"+r;
                        else if(e/r<(float)e/r)b=e/r+"'"+(e-e/r*r)+"/"+r;
                        else b=String.valueOf(e/r);
                    }
                    if(c.equals("0")||t/y>=k) {
                        t=new Random().nextInt(k);
                        y=new Random().nextInt(k-1)+1;
                        s3=huajian(y,t);
                        s33=s3.split("\\/");
                        t=Integer.valueOf(s33[0]);
                        y=Integer.valueOf(s33[1]);
                        if(t==0)c=String.valueOf(t);
                        else if(t/y==0)c=t+"/"+y;
                        else if(t/y<(float)t/y)c=t/y+"'"+(t-t/y*y)+"/"+y;
                        else c=String.valueOf(t/y);
                    }
                    if(d.equals("0")||m/n>=k) {
                        m=new Random().nextInt(k);
                        n=new Random().nextInt(k-1)+1;
                        s3=huajian(n,m);
                        s33=s3.split("\\/");
                        m=Integer.valueOf(s33[0]);
                        n=Integer.valueOf(s33[1]);
                        if(m==0)d=String.valueOf(m);
                        else if(m/n==0)d=m+"/"+n;
                        else if(m/n<(float)m/n)d=m/n+"'"+(m-m/n*n)+"/"+n;
                        else c=String.valueOf(m/n);
                    }
                }
                while(op1.equals("÷")&&!op2.equals("÷")&&op3.equals("÷")
                        &&b.equals("0")||d.equals("0")||e/r>=k||m/n>=k) {
                    if(b.equals("0")||e/r>=k) {
                        e=new Random().nextInt(k);
                        r=new Random().nextInt(k-1)+1;
                        s2=huajian(r,e);
                        s22=s2.split("\\/");
                        e=Integer.valueOf(s22[0]);
                        r=Integer.valueOf(s22[1]);
                        if(e==0)b=String.valueOf(e);
                        else if(e/r==0)b=e+"/"+r;
                        else if(e/r<(float)e/r)b=e/r+"'"+(e-e/r*r)+"/"+r;
                        else b=String.valueOf(e/r);
                    }
                    if(d.equals("0")||m/n>=k) {
                        m=new Random().nextInt(k);
                        n=new Random().nextInt(k-1)+1;
                        s3=huajian(n,m);
                        s33=s3.split("\\/");
                        m=Integer.valueOf(s33[0]);
                        n=Integer.valueOf(s33[1]);
                        if(m==0)d=String.valueOf(m);
                        else if(m/n==0)d=m+"/"+n;
                        else if(m/n<(float)m/n)d=m/n+"'"+(m-m/n*n)+"/"+n;
                        else c=String.valueOf(m/n);
                    }
                }
                while(op1.equals("÷")&&!op2.equals("÷")&&!op3.equals("÷")
                        &&b.equals("0")||e/r>=k) {
                    if(b.equals("0")||e/r>=k) {
                        e=new Random().nextInt(k);
                        r=new Random().nextInt(k-1)+1;
                        s2=huajian(r,e);
                        s22=s2.split("\\/");
                        e=Integer.valueOf(s22[0]);
                        r=Integer.valueOf(s22[1]);
                        if(e==0)b=String.valueOf(e);
                        else if(e/r==0)b=e+"/"+r;
                        else if(e/r<(float)e/r)b=e/r+"'"+(e-e/r*r)+"/"+r;
                        else b=String.valueOf(e/r);
                    }
                }
                    while(!op1.equals("÷")&&op2.equals("÷")&&!op3.equals("÷")
                            &&c.equals("0")||t/y>=k) {
                        if(c.equals("0")||t/y>=k) {
                            t=new Random().nextInt(k);
                            y=new Random().nextInt(k-1)+1;
                            s3=huajian(y,t);
                            s33=s3.split("\\/");
                            t=Integer.valueOf(s33[0]);
                            y=Integer.valueOf(s33[1]);
                            if(t==0)c=String.valueOf(t);
                            else if(t/y==0)c=t+"/"+y;
                            else if(t/y<(float)t/y)c=t/y+"'"+(t-t/y*y)+"/"+y;
                            else c=String.valueOf(t/y);
                        }
                    }
                    while(!op1.equals("÷")&&op2.equals("÷")&&op3.equals("÷")
                            &&c.equals("0")||d.equals("0")||t/y>=k||m/n>=k) {
                        if(c.equals("0")||t/y>=k) {
                            t=new Random().nextInt(k);
                            y=new Random().nextInt(k-1)+1;
                            s3=huajian(y,t);
                            s33=s3.split("\\/");
                            t=Integer.valueOf(s33[0]);
                            y=Integer.valueOf(s33[1]);
                            if(t==0)c=String.valueOf(t);
                            else if(t/y==0)c=t+"/"+y;
                            else if(t/y<(float)t/y)c=t/y+"'"+(t-t/y*y)+"/"+y;
                            else c=String.valueOf(t/y);
                        }
                        if(d.equals("0")||m/n>=k) {
                            m=new Random().nextInt(k);
                            n=new Random().nextInt(k-1)+1;
                            s3=huajian(n,m);
                            s33=s3.split("\\/");
                            m=Integer.valueOf(s33[0]);
                            n=Integer.valueOf(s33[1]);
                            if(m==0)d=String.valueOf(m);
                            else if(m/n==0)d=m+"/"+n;
                            else if(m/n<(float)m/n)d=m/n+"'"+(m-m/n*n)+"/"+n;
                            else c=String.valueOf(m/n);
                        }
                    }
                    while(!op1.equals("÷")&&op2.equals("÷")&&op3.equals("÷")
                            &&d.equals("0")||m/n>=k) {
                        if(d.equals("0")||m/n>=k) {
                            m=new Random().nextInt(k);
                            n=new Random().nextInt(k-1)+1;
                            s3=huajian(n,m);
                            s33=s3.split("\\/");
                            m=Integer.valueOf(s33[0]);
                            n=Integer.valueOf(s33[1]);
                            if(m==0)d=String.valueOf(m);
                            else if(m/n==0)d=m+"/"+n;
                            else if(m/n<(float)m/n)d=m/n+"'"+(m-m/n*n)+"/"+n;
                            else c=String.valueOf(m/n);
                        }
                    }
                    while(op1.equals("÷")&&op2.equals("÷")&&!op3.equals("÷")
                            &&b.equals("0")||c.equals("0")||e/r>=k||t/y>=k) {
                        if(b.equals("0")||e/r>=k) {
                            e=new Random().nextInt(k);
                            r=new Random().nextInt(k-1)+1;
                            s2=huajian(r,e);
                            s22=s2.split("\\/");
                            e=Integer.valueOf(s22[0]);
                            r=Integer.valueOf(s22[1]);
                            if(e==0)b=String.valueOf(e);
                            else if(e/r==0)b=e+"/"+r;
                            else if(e/r<(float)e/r)b=e/r+"'"+(e-e/r*r)+"/"+r;
                            else b=String.valueOf(e/r);
                        }
                        if(c.equals("0")||t/y>=k) {
                            t=new Random().nextInt(k);
                            y=new Random().nextInt(k-1)+1;
                            s3=huajian(y,t);
                            s33=s3.split("\\/");
                            t=Integer.valueOf(s33[0]);
                            y=Integer.valueOf(s33[1]);
                            if(t==0)c=String.valueOf(t);
                            else if(t/y==0)c=t+"/"+y;
                            else if(t/y<(float)t/y)c=t/y+"'"+(t-t/y*y)+"/"+y;
                            else c=String.valueOf(t/y);
                        }
                    }
                if(op1.equals("×")||op1.equals("÷"))s=a+op1+b+op2+c+op3+d;
                else if(op2.equals("+")||op2.equals("-"))s=a+op1+b+op2+c+op3+d;
                else s="("+a+op1+b+")"+op2+c+op3+d;
                break;
            }
            case 3:{
                while(op1.equals("÷")
                        &&d.equals("0")||b.equals("0")||c.equals("0")||m/n>=k||t/y>=k||e/r>=k) {
                    if(b.equals("0")||e/r>=k) {
                        e=new Random().nextInt(k);
                        r=new Random().nextInt(k-1)+1;
                        s2=huajian(r,e);
                        s22=s2.split("\\/");
                        e=Integer.valueOf(s22[0]);
                        r=Integer.valueOf(s22[1]);
                        if(e==0)b=String.valueOf(e);
                        else if(e/r==0)b=e+"/"+r;
                        else if(e/r<(float)e/r)b=e/r+"'"+(e-e/r*r)+"/"+r;
                        else b=String.valueOf(e/r);
                    }
                    if(c.equals("0")||t/y>=k) {
                        t=new Random().nextInt(k);
                        y=new Random().nextInt(k-1)+1;
                        s3=huajian(y,t);
                        s33=s3.split("\\/");
                        t=Integer.valueOf(s33[0]);
                        y=Integer.valueOf(s33[1]);
                        if(t==0)c=String.valueOf(t);
                        else if(t/y==0)c=t+"/"+y;
                        else if(t/y<(float)t/y)c=t/y+"'"+(t-t/y*y)+"/"+y;
                        else c=String.valueOf(t/y);
                    }
                    if(d.equals("0")||m/n>=k) {
                        m=new Random().nextInt(k);
                        n=new Random().nextInt(k-1)+1;
                        s3=huajian(n,m);
                        s33=s3.split("\\/");
                        m=Integer.valueOf(s33[0]);
                        n=Integer.valueOf(s33[1]);
                        if(m==0)d=String.valueOf(m);
                        else if(m/n==0)d=m+"/"+n;
                        else if(m/n<(float)m/n)d=m/n+"'"+(m-m/n*n)+"/"+n;
                        else c=String.valueOf(m/n);
                    }
                }
                while(!op1.equals("÷")&&op2.equals("÷")&&!op3.equals("÷")
                        &&c.equals("0")||t/y>=k) {
                    if(c.equals("0")||t/y>=k) {
                        t=new Random().nextInt(k);
                        y=new Random().nextInt(k-1)+1;
                        s3=huajian(y,t);
                        s33=s3.split("\\/");
                        t=Integer.valueOf(s33[0]);
                        y=Integer.valueOf(s33[1]);
                        if(t==0)c=String.valueOf(t);
                        else if(t/y==0)c=t+"/"+y;
                        else if(t/y<(float)t/y)c=t/y+"'"+(t-t/y*y)+"/"+y;
                        else c=String.valueOf(t/y);
                    }
                }
                while(!op1.equals("÷")&&op2.equals("÷")&&op3.equals("÷")
                        &&c.equals("0")||d.equals("0")||t/y>=k||m/n>=k) {
                    if(c.equals("0")||t/y>=k) {
                        t=new Random().nextInt(k);
                        y=new Random().nextInt(k-1)+1;
                        s3=huajian(y,t);
                        s33=s3.split("\\/");
                        t=Integer.valueOf(s33[0]);
                        y=Integer.valueOf(s33[1]);
                        if(t==0)c=String.valueOf(t);
                        else if(t/y==0)c=t+"/"+y;
                        else if(t/y<(float)t/y)c=t/y+"'"+(t-t/y*y)+"/"+y;
                        else c=String.valueOf(t/y);
                    }
                    if(d.equals("0")||m/n>=k) {
                        m=new Random().nextInt(k);
                        n=new Random().nextInt(k-1)+1;
                        s3=huajian(n,m);
                        s33=s3.split("\\/");
                        m=Integer.valueOf(s33[0]);
                        n=Integer.valueOf(s33[1]);
                        if(m==0)d=String.valueOf(m);
                        else if(m/n==0)d=m+"/"+n;
                        else if(m/n<(float)m/n)d=m/n+"'"+(m-m/n*n)+"/"+n;
                        else c=String.valueOf(m/n);
                    }
                }
                while(!op1.equals("÷")&&!op2.equals("÷")&&op3.equals("÷")
                        &&d.equals("0")||m/n>=k) {
                    if(d.equals("0")||m/n>=k) {
                        m=new Random().nextInt(k);
                        n=new Random().nextInt(k-1)+1;
                        s3=huajian(n,m);
                        s33=s3.split("\\/");
                        m=Integer.valueOf(s33[0]);
                        n=Integer.valueOf(s33[1]);
                        if(m==0)d=String.valueOf(m);
                        else if(m/n==0)d=m+"/"+n;
                        else if(m/n<(float)m/n)d=m/n+"'"+(m-m/n*n)+"/"+n;
                        else c=String.valueOf(m/n);
                    }
                }
                s=a+op1+"("+b+op2+c+op3+d+")";
                break;
            }
            case 4:{
                while(op1.equals("÷")&&!(!op2.equals("÷")&&!op3.equals("÷"))
                        &&b.equals("0")||c.equals("0")||d.equals("0")||e/r>=k||t/y>=k||m/n>=k) {
                    if(b.equals("0")||e/r>=k) {
                        e=new Random().nextInt(k);
                        r=new Random().nextInt(k-1)+1;
                        s2=huajian(r,e);
                        s22=s2.split("\\/");
                        e=Integer.valueOf(s22[0]);
                        r=Integer.valueOf(s22[1]);
                        if(e==0)b=String.valueOf(e);
                        else if(e/r==0)b=e+"/"+r;
                        else if(e/r<(float)e/r)b=e/r+"'"+(e-e/r*r)+"/"+r;
                        else b=String.valueOf(e/r);
                    }
                    if(c.equals("0")||t/y>=k) {
                        t=new Random().nextInt(k);
                        y=new Random().nextInt(k-1)+1;
                        s3=huajian(y,t);
                        s33=s3.split("\\/");
                        t=Integer.valueOf(s33[0]);
                        y=Integer.valueOf(s33[1]);
                        if(t==0)c=String.valueOf(t);
                        else if(t/y==0)c=t+"/"+y;
                        else if(t/y<(float)t/y)c=t/y+"'"+(t-t/y*y)+"/"+y;
                        else c=String.valueOf(t/y);
                    }
                    if(d.equals("0")||m/n>=k) {
                        m=new Random().nextInt(k);
                        n=new Random().nextInt(k-1)+1;
                        s3=huajian(n,m);
                        s33=s3.split("\\/");
                        m=Integer.valueOf(s33[0]);
                        n=Integer.valueOf(s33[1]);
                        if(m==0)d=String.valueOf(m);
                        else if(m/n==0)d=m+"/"+n;
                        else if(m/n<(float)m/n)d=m/n+"'"+(m-m/n*n)+"/"+n;
                        else c=String.valueOf(m/n);
                    }
                }
                while(op1.equals("÷")&&!op3.equals("÷")
                        &&b.equals("0")||c.equals("0")||e/r>=k||t/y>=k) {
                    if(b.equals("0")||e/r>=k) {
                        e=new Random().nextInt(k);
                        r=new Random().nextInt(k-1)+1;
                        s2=huajian(r,e);
                        s22=s2.split("\\/");
                        e=Integer.valueOf(s22[0]);
                        r=Integer.valueOf(s22[1]);
                        if(e==0)b=String.valueOf(e);
                        else if(e/r==0)b=e+"/"+r;
                        else if(e/r<(float)e/r)b=e/r+"'"+(e-e/r*r)+"/"+r;
                        else b=String.valueOf(e/r);
                    }
                    if(c.equals("0")||t/y>=k) {
                        t=new Random().nextInt(k);
                        y=new Random().nextInt(k-1)+1;
                        s3=huajian(y,t);
                        s33=s3.split("\\/");
                        t=Integer.valueOf(s33[0]);
                        y=Integer.valueOf(s33[1]);
                        if(t==0)c=String.valueOf(t);
                        else if(t/y==0)c=t+"/"+y;
                        else if(t/y<(float)t/y)c=t/y+"'"+(t-t/y*y)+"/"+y;
                        else c=String.valueOf(t/y);
                    }
                }
                while(!op1.equals("÷")&&op2.equals("÷")&&op3.equals("÷")
                        &&c.equals("0")||d.equals("0")||t/y>=k||m/n>=k) {
                    if(c.equals("0")||t/y>=k) {
                        t=new Random().nextInt(k);
                        y=new Random().nextInt(k-1)+1;
                        s3=huajian(y,t);
                        s33=s3.split("\\/");
                        t=Integer.valueOf(s33[0]);
                        y=Integer.valueOf(s33[1]);
                        if(t==0)c=String.valueOf(t);
                        else if(t/y==0)c=t+"/"+y;
                        else if(t/y<(float)t/y)c=t/y+"'"+(t-t/y*y)+"/"+y;
                        else c=String.valueOf(t/y);
                    }
                    if(d.equals("0")||m/n>=k) {
                        m=new Random().nextInt(k);
                        n=new Random().nextInt(k-1)+1;
                        s3=huajian(n,m);
                        s33=s3.split("\\/");
                        m=Integer.valueOf(s33[0]);
                        n=Integer.valueOf(s33[1]);
                        if(m==0)d=String.valueOf(m);
                        else if(m/n==0)d=m+"/"+n;
                        else if(m/n<(float)m/n)d=m/n+"'"+(m-m/n*n)+"/"+n;
                        else c=String.valueOf(m/n);
                    }
                }
                while(!op1.equals("÷")&&op2.equals("÷")&&!op3.equals("÷")
                        &&c.equals("0")||t/y>=k) {
                    if(c.equals("0")||t/y>=k) {
                        t=new Random().nextInt(k);
                        y=new Random().nextInt(k-1)+1;
                        s3=huajian(y,t);
                        s33=s3.split("\\/");
                        t=Integer.valueOf(s33[0]);
                        y=Integer.valueOf(s33[1]);
                        if(t==0)c=String.valueOf(t);
                        else if(t/y==0)c=t+"/"+y;
                        else if(t/y<(float)t/y)c=t/y+"'"+(t-t/y*y)+"/"+y;
                        else c=String.valueOf(t/y);
                    }
                }
                while(!op1.equals("÷")&&!op2.equals("÷")&&op3.equals("÷")
                        &&d.equals("0")||m/n>=k) {
                    if(d.equals("0")||m/n>=k) {
                        m=new Random().nextInt(k);
                        n=new Random().nextInt(k-1)+1;
                        s3=huajian(n,m);
                        s33=s3.split("\\/");
                        m=Integer.valueOf(s33[0]);
                        n=Integer.valueOf(s33[1]);
                        if(m==0)d=String.valueOf(m);
                        else if(m/n==0)d=m+"/"+n;
                        else if(m/n<(float)m/n)d=m/n+"'"+(m-m/n*n)+"/"+n;
                        else c=String.valueOf(m/n);
                    }
                }
                if(op2.equals("+")||op2.equals("-"))s=a+op1+"("+b+op2+c+")"+op3+d;
                else if(op1.equals("×")||op1.equals("÷"))s=a+op1+"("+b+op2+c+")"+op3+d;
                else s=a+op1+b+op2+c+op3+d;
                break;
            }
            case 5:{
                while(op1.equals("÷")&&op2.equals("÷")
                        &&b.equals("0")||c.equals("0")||d.equals("0")||m/n>=k||t/y>=k||e/r>=k) {
                    if(b.equals("0")||e/r>=k) {
                        e=new Random().nextInt(k);
                        r=new Random().nextInt(k-1)+1;
                        s2=huajian(r,e);
                        s22=s2.split("\\/");
                        e=Integer.valueOf(s22[0]);
                        r=Integer.valueOf(s22[1]);
                        if(e==0)b=String.valueOf(e);
                        else if(e/r==0)b=e+"/"+r;
                        else if(e/r<(float)e/r)b=e/r+"'"+(e-e/r*r)+"/"+r;
                        else b=String.valueOf(e/r);
                    }
                    if(c.equals("0")||t/y>=k) {
                        t=new Random().nextInt(k);
                        y=new Random().nextInt(k-1)+1;
                        s3=huajian(y,t);
                        s33=s3.split("\\/");
                        t=Integer.valueOf(s33[0]);
                        y=Integer.valueOf(s33[1]);
                        if(t==0)c=String.valueOf(t);
                        else if(t/y==0)c=t+"/"+y;
                        else if(t/y<(float)t/y)c=t/y+"'"+(t-t/y*y)+"/"+y;
                        else c=String.valueOf(t/y);
                    }
                    if(d.equals("0")||m/n>=k) {
                        m=new Random().nextInt(k);
                        n=new Random().nextInt(k-1)+1;
                        s3=huajian(n,m);
                        s33=s3.split("\\/");
                        m=Integer.valueOf(s33[0]);
                        n=Integer.valueOf(s33[1]);
                        if(m==0)d=String.valueOf(m);
                        else if(m/n==0)d=m+"/"+n;
                        else if(m/n<(float)m/n)d=m/n+"'"+(m-m/n*n)+"/"+n;
                        else c=String.valueOf(m/n);
                    }
                }
                while(op1.equals("÷")&&!op2.equals("÷")&&op3.equals("÷")
                        &&b.equals("0")||d.equals("0")||m/n>=k||e/r>=k) {
                    if(b.equals("0")||e/r>=k) {
                        e=new Random().nextInt(k);
                        r=new Random().nextInt(k-1)+1;
                        s2=huajian(r,e);
                        s22=s2.split("\\/");
                        e=Integer.valueOf(s22[0]);
                        r=Integer.valueOf(s22[1]);
                        if(e==0)b=String.valueOf(e);
                        else if(e/r==0)b=e+"/"+r;
                        else if(e/r<(float)e/r)b=e/r+"'"+(e-e/r*r)+"/"+r;
                        else b=String.valueOf(e/r);
                    }
                    if(d.equals("0")||m/n>=k) {
                        m=new Random().nextInt(k);
                        n=new Random().nextInt(k-1)+1;
                        s3=huajian(n,m);
                        s33=s3.split("\\/");
                        m=Integer.valueOf(s33[0]);
                        n=Integer.valueOf(s33[1]);
                        if(m==0)d=String.valueOf(m);
                        else if(m/n==0)d=m+"/"+n;
                        else if(m/n<(float)m/n)d=m/n+"'"+(m-m/n*n)+"/"+n;
                        else c=String.valueOf(m/n);
                    }
                }
                while(!op1.equals("÷")&&op2.equals("÷")
                        &&c.equals("0")||d.equals("0")||t/y>=k||m/n>=k) {
                    if(c.equals("0")||t/y>=k) {
                        t=new Random().nextInt(k);
                        y=new Random().nextInt(k-1)+1;
                        s3=huajian(y,t);
                        s33=s3.split("\\/");
                        t=Integer.valueOf(s33[0]);
                        y=Integer.valueOf(s33[1]);
                        if(t==0)c=String.valueOf(t);
                        else if(t/y==0)c=t+"/"+y;
                        else if(t/y<(float)t/y)c=t/y+"'"+(t-t/y*y)+"/"+y;
                        else c=String.valueOf(t/y);
                    }
                    if(d.equals("0")||m/n>=k) {
                        m=new Random().nextInt(k);
                        n=new Random().nextInt(k-1)+1;
                        s3=huajian(n,m);
                        s33=s3.split("\\/");
                        m=Integer.valueOf(s33[0]);
                        n=Integer.valueOf(s33[1]);
                        if(m==0)d=String.valueOf(m);
                        else if(m/n==0)d=m+"/"+n;
                        else if(m/n<(float)m/n)d=m/n+"'"+(m-m/n*n)+"/"+n;
                        else c=String.valueOf(m/n);
                    }
                }
                while(op1.equals("÷")&&!op2.equals("÷")&&!op3.equals("÷")
                        &&b.equals("0")||e/r>=k) {
                    if(b.equals("0")||e/r>=k) {
                        e=new Random().nextInt(k);
                        r=new Random().nextInt(k-1)+1;
                        s2=huajian(r,e);
                        s22=s2.split("\\/");
                        e=Integer.valueOf(s22[0]);
                        r=Integer.valueOf(s22[1]);
                        if(e==0)b=String.valueOf(e);
                        else if(e/r==0)b=e+"/"+r;
                        else if(e/r<(float)e/r)b=e/r+"'"+(e-e/r*r)+"/"+r;
                        else b=String.valueOf(e/r);
                    }
                }
                while(!op1.equals("÷")&&!op2.equals("÷")&&op3.equals("÷")
                        &&d.equals("0")||m/n>=k) {
                    if(d.equals("0")||m/n>=k) {
                        m=new Random().nextInt(k);
                        n=new Random().nextInt(k-1)+1;
                        s3=huajian(n,m);
                        s33=s3.split("\\/");
                        m=Integer.valueOf(s33[0]);
                        n=Integer.valueOf(s33[1]);
                        if(m==0)d=String.valueOf(m);
                        else if(m/n==0)d=m+"/"+n;
                        else if(m/n<(float)m/n)d=m/n+"'"+(m-m/n*n)+"/"+n;
                        else c=String.valueOf(m/n);
                    }
                }
                if(op2.equals("÷")||op2.equals("×"))s=a+op1+b+op2+"("+c+op3+d+")";
                else if(op3.equals("÷")||op3.equals("×"))s=a+op1+b+op2+c+op3+d;
                else s=a+op1+b+op2+"("+c+op3+d+")";
                break;
            }
            }
            return s;
        }
        return null;
    }
    
    public static String huajian(int int5,int int6) {  //化简分数,int5为分母,int6为分子
        int greatest_common = greatest_common(int5,int6);
        String st8 = String.valueOf(int6/greatest_common)+"/"+String.valueOf(int5/greatest_common);
        return st8;
        }
    
    public static int greatest_common(int x, int y){  //辗转相除法求最大公约数
        if(y == 0)
        return x;
        else
        return greatest_common(y,x%y);
        }
}

duplicate_checking.java(查重)

import java.util.Stack;

public class duplicate_checking {
    
    Stack<String> stack=new Stack<>();//存放除运算数的字符串
    int i,j,k;
    String a[]=new String[100];//存放数字
    String b[]=new String[100];
    String temp;

    Nope cnki(String s){
        i=0;j=0;k=0;
        while(j<s.length()) {//中缀表达式转化为后缀表达式
            temp=s.substring(j,j+1);
            if(temp.matches("\\d+")||temp.equals("'")||temp.equals("/")) {//对操作数存储,用数组实现
                a[i++]=temp;
                while(temp.matches("\\d+")||temp.equals("'")||temp.equals("/")) {
                    if(j+1==s.length())break;
                    temp=s.substring(j+1,j+2);
                    if(temp.matches("\\d+")||temp.equals("'")||temp.equals("/")) {
                        a[i-1]+=temp;
                        j++;
                    }    
                }
                b[k++]=a[i-1];
            }
            else {
                if(stack.empty())stack.push(temp);
                else if(temp.equals("("))stack.push(temp);
                else if(stack.peek().equals("("))stack.push(temp);
                else if(temp.equals(")")) {
                    while(!stack.peek().equals("("))b[k++]=stack.pop();
                    stack.pop();
                }
                else {
                    if(prior(temp)>prior(stack.peek()))stack.push(temp);
                    else {
                        do {
                            b[k++]=stack.pop();
                            if(stack.empty()||stack.peek().equals("("))break;
                        }while(prior(temp)<=prior(stack.peek()));
                        stack.push(temp);
                    }
                }
            }
            j++;
        }
        while(!stack.empty())b[k++]=stack.pop();
        b[k]=null;
        int m=0;
        while(b[m]!=null) m++;
        return new Nope().BiTree(b,m-1);
    }
    
    int prior(String s) {//运算优先级的判断
        if(s.equals("+")||s.equals("-"))return 0;
        else return 1;
    }
    
}
class Nope{
    
    String value;//结点的值
    Nope lc,rc;//左右孩子 

    Nope BiTree(String s[],int i){//构建二叉树
        Nope p=new Nope();
        Nope temp=new Nope();

        p.value=s[i];    
        if(p.value.matches("\\+|\\-|\\×|\\÷"))p.rc=BiTree(s,i-1);
        temp=p;
        int count=0;
        if(p.value.matches("\\+|\\-|\\×|\\÷")) {while(temp.rc.value.matches("\\+|\\-|\\×|\\÷")) {
            temp=temp.rc;
            count++;
        }
        count=count+1;
        }
        if(p.value.matches("\\+|\\-|\\×|\\÷"))p.lc=BiTree(s,i-2*count);
        return p;
    }
    
    public boolean compare(Nope p,Nope q) {
        if(p.value.equals(q.value)) {
            if(!p.value.matches("\\+|\\-|\\×|\\÷"))return true;
            return compare(p.lc,q.lc)&&compare(p.rc,q.rc)||compare(p.lc,q.rc)&&compare(p.rc,q.lc);
            
        }
        else return false;
    }
}

create_only.java(生成唯一表达式)

import java.util.ArrayList;

public class create_only {
    static GeneratingExpression ge = new GeneratingExpression();
    main m = new main();
    static duplicate_checking dc = new duplicate_checking();
    static Nope nope = new Nope();
            
    public String cha() {
    String s2 = ge.GeneratingExpression(Integer.parseInt(m.sz1[2]));
      if(m.chachong.size()==0) {
      m.chachong.add(s2);
      }
      else {
          for(int p=0;p<m.chachong.size();p++) {
              if(!nope.compare(dc.cnki(s2),dc.cnki(m.chachong.get(p)))) {}
              else {return cha();}
          }
      }
      m.chachong.add(s2);
      return s2;
}
}

readAnswer.java(读标准答案文件)

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

public class readAnswer {
List<String> list1 = new ArrayList<String>();
    
    public List<String> read (String s) {
    try {
        File file = new File(s);
        if(file.isFile() && file.exists()) { //当文件正常且存在
        InputStreamReader in = new InputStreamReader(new FileInputStream(file), "utf-8");
        BufferedReader br = new BufferedReader(in); //从字符输入流中读取文本,缓冲各个字符,从而提供字符、数组和行的高效读取
        String aa = null;
        while ((aa = br.readLine()) != null) {
            list1.add(aa);
        }
         br.close();
        } else {
            System.out.println("文件不存在!");
        }
    } catch (UnsupportedEncodingException e) {
        System.out.println("字符编码不支持");
    } catch (FileNotFoundException e) {
        System.out.println("找不到指定文件");
    } catch (IOException e) {
        System.out.println("I/O错误");
    }
    return list1;
    }     
}

readFile.java(读取作答文件)

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

public class readFile {
List<String> list1 = new ArrayList<String>();
    
    public List<String> read(String s) {
    try {
        File file = new File(s);
        if(file.isFile() && file.exists()) { //当文件正常且存在
        InputStreamReader in = new InputStreamReader(new FileInputStream(file), "utf-8");
        BufferedReader br = new BufferedReader(in); //从字符输入流中读取文本,缓冲各个字符,从而提供字符、数组和行的高效读取
        String aa = null;
        while ((aa = br.readLine()) != null) {
            list1.add(aa);
        }
         br.close();
        } else {
            System.out.println("文件不存在!");
        }
    } catch (UnsupportedEncodingException e) {
        System.out.println("字符编码不支持");
    } catch (FileNotFoundException e) {
        System.out.println("找不到指定文件");
    } catch (IOException e) {
        System.out.println("I/O错误");
    }
    return list1;
    }     
}

saveAnswers.java(存入答案)

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class saveAnswers {
    private static String path = "F:\\Answers.txt";
       int i = 1;
       public void xieru(String s){
            OutputStream out;
            try {
                out = getOutputStream();
                String ss = String.valueOf(i)+".";
                out.write(ss.getBytes()); //写入题的序号
                out.write("  ".getBytes()); //序号后写入空格于题目分隔开
                out.write(s.getBytes("utf-8"));//写入题目
                out.write("\r\n".getBytes());//写入换行
                i++;
            } catch (IOException e) {
                System.out.println("xieru方法I/O错误");
            }         
    }

       public static OutputStream getOutputStream(){
          try {
            File file = new File(path); //先创建File类对象,存入文件路径
              if (!file.exists()) {
              file.createNewFile(); //如文件不存在则创建文件
               }
              return new FileOutputStream(file,true);//再实例化FileOutputStream,参数设置为true才不会覆盖之前写入的东西
        } catch (FileNotFoundException e) {
            System.out.println("找不到指定文件");
        } catch (IOException e) {
            System.out.println("getOutputStream方法I/O错误");
        }
        return null;
      }
}

saveExercises.java(存入题目)

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class saveExercises {
   private static String path = "F:\\Exercises.txt";
   main ma = new main();
   int i = 1;
   public void xieru(String s){
        OutputStream out;
        try {
            out = getOutputStream();
            String ss = String.valueOf(i)+".";
            out.write(ss.getBytes()); //写入题的序号
            out.write("  ".getBytes()); //序号后写入空格于题目分隔开
            out.write(s.getBytes("utf-8"));//写入题目
            out.write("\r\n".getBytes());//写入换行
            i++;
        } catch (IOException e) {
            System.out.println("xieru方法I/O错误");
        }         
}

   public static OutputStream getOutputStream(){
      try {
        File file = new File(path); //先创建File类对象,存入文件路径
          if (!file.exists()) {
          file.createNewFile(); //如文件不存在则创建文件
           }
          return new FileOutputStream(file,true);//再实例化FileOutputStream,参数设置为true才不会覆盖之前写入的东西
    } catch (FileNotFoundException e) {
        System.out.println("找不到指定文件");
    } catch (IOException e) {
        System.out.println("getOutputStream方法I/O错误");
    }
    return null;
  }
}

main.java

import java.util.ArrayList;
import java.util.Scanner;

public class main {
    
    static int exerciseNum;
    static String[] sz1;
    static String s1;
    static calculate cc= new calculate();
    static create_only aa1 = new create_only();
    static GeneratingExpression ge = new GeneratingExpression();
    static saveExercises sa = new saveExercises();
    static saveAnswers sa1 = new saveAnswers();
    static readFile rf = new readFile();
    static readAnswer ra = new readAnswer();
    static ArrayList<Integer> T=new ArrayList<Integer>();
    static ArrayList<Integer> F=new ArrayList<Integer>();
    static ArrayList<String> chachong=new ArrayList<String>();
    private static Scanner sn1;
    static duplicate_checking dc = new duplicate_checking();
    static Nope nope = new Nope();
    
    public static void main(String[] args) {
        sn1 = new Scanner(System.in);
        
        if(sn1.hasNext()) { //如果有输入
            s1 = sn1.nextLine();
            
            if(s1.contains("-n")&&(s1.substring(s1.indexOf("r")+2, s1.length())).matches("\\d+")) { //生成题目与答案
              sz1 = s1.split("\\D+");//sz1[1]存题数,sz1[2]存数范围
              exerciseNum= Integer.parseInt(sz1[1]);
                for(int i=0;i<Integer.parseInt(sz1[1]);i++) {
                    String s2 = aa1.cha();
                  sa.xieru(s2+"=");
                  String s3 = cc.jisuan(s2);
                  sa1.xieru(s3);
                }        
                System.out.println("成功生成题目与答案!");
            }
            
            else if(s1.contains("-e")) { //改错功能
            String t = s1.substring(s1.indexOf("e")+2,s1.indexOf("a")-2);//存题目地址
            String d = s1.substring(s1.indexOf("a")+2,s1.length());//存作答地址
            int u=rf.read(t).size();
            for(int ii=0;ii<u;ii++){
                if((rf.read(t).get(ii)).equals(ra.read(d).get(ii))) {
                    T.add(ii+1);
                }
                else {
                    F.add(ii+1);
                }
            }
            System.out.print("Correct: "+T.size()+"("); //打印正确的题数与题目号
            for(int i=0;i<T.size();i++) {
                if(!(i==T.size()-1)) {
                   System.out.print(T.get(i)+",");
                }
                else {
                    System.out.print(T.get(i));
                }
            }
            System.out.println(")");
            
            System.out.print("Wrong: "+F.size()+"("); //打印错误的题数与题目号
            for(int i=0;i<F.size();i++) {
                if(!(i==F.size()-1)) {
                   System.out.print(F.get(i)+",");
                }
                else {
                System.out.print(F.get(i));
                }
            }
            System.out.print(")");
        }
        else System.out.println("请输入有效命令");
        }
        else System.out.println("请输入命令");
    }
}

七、运行结果

 

 

 

同理,生成10000道:

八、实际花费时间

如第三点psp表所示。

 

九、项目小结

        本次项目为结对项目,在刚开始做项目的时候,我们两个人对这个项目的具体框架内容并不是特别清晰。导致一开始的分工并不是特别清楚,只进行了大概的分工。在做项目的过程中,由于很多东西没有事先想清楚,导致等到写到一些部分的时候与别的部分有所冲突。在项目进行到一半的时候,很多具体的分工、写法才确定下来,虽然因此拖慢了进度,但是在不断的交流中还是修正完善了许多功能,到最后项目的完成。因此在以后的结对项目中,具体各个部分的功能内容最好要先思考清楚,分工明确之后编写项目的效率会更高。在做结对项目的过程中,我们也提高了编码的熟练度,对代码编写的许多知识也有所学习。

   评价:

          卢泰佑:在和队友李密讨论的过程中,我发现了一些在编写代码过程中的一些不足与错误,同时他也根据我们的计划去认真实现,由此使结对项目完成得更好。

          李密:在和队友得讨论中改善了许多功能,他也提出了一些更好的建议,使我们在交流中完善了许多功能。

posted on 2018-09-30 20:41  lu_ty  阅读(390)  评论(0)    收藏  举报

导航