结对项目
| 这个作业属于哪个课程 | https://edu.cnblogs.com/campus/gdgy/CSGrade22-12 | 
|---|---|
| 这个作业要求在哪里 | https://edu.cnblogs.com/campus/gdgy/CSGrade22-12/homework/13221 | 
| 队伍成员 | 阿依努尔•麦麦提艾麦尔 3222004805 努日曼姑丽·阿卜来孜 3222004935 | 
| 这个作业目标 | 实现一个自动生成小学四则运算题目的命令行程序 | 
| Github项目地址 | https://github.com/3636492812/3636492812 | 
| PSP2.1 | Personal Software Process Stages | 预估耗时 (分钟) | 实际耗时(分钟) | 
|---|---|---|---|
| Planning | 计划 | 30 | 30 | 
| ·Estimate | ·估计这个任务需要多少时间 | 30 | 30 | 
| Development | 开发 | 1010 | 1370 | 
| ·Analysis | ·需求分析(包括学习新技术) | 50 | 40 | 
| ·Design Spec | ·生成设计文档 | 20 | 20 | 
| ·Design Review | ·设计复审 | 10 | 5 | 
| ·Coding Standard | ·代码规范(为目前的开发制定合适的规范) | 10 | 15 | 
| ·Design | ·具体设计 | 30 | 40 | 
| ·Coding | ·具体编码 | 850 | 1150 | 
| ·Code Review | ·代码复审 | 30 | 60 | 
| ·Test | ·测试(自我测试,修改代码,提交修改) | 10 | 40 | 
| Reporting | 报告 | 65 | 75 | 
| ·Test Repor | ·测试报告 | 30 | 40 | 
| ·Size Measurement | ·计算工作量 | 15 | 10 | 
| ·Postmortem & Process Improvement Plan | ·事后总结,并提出过程改进计划 | 20 | 25 | 
| 合计 | 1475 | 1720 | 
具体代码实现
public static void main(String[] args){
     Scanner sc= new Scanner(System.in);
     System.out.println("请输入产生几以内的数字:");
     range=sc.nextInt();
     System.out.println("请输入产生多少个运算表达式:");
     int num=sc.nextInt();
     int rightcount[]=new int[num+2];
     int wrongcount[]=new int[num+2];
     int right1=0;
    int wrong1=0;
    String[] results=new String[num];int i;
     for( i=0;i<num;i++){ 
          /*具体的功能如下面的代码(两个class除外)*/
}
生成题目:
String expArr[]=new String[2];//定义生成的题目
        int a= (int) (random.nextInt(range));//分子
        int b= (int) (random.nextInt(range));//分母
        int c= (int) (random.nextInt(range));//另一个分子
        int d= (int) (random.nextInt(range));//另一个分母
        int fuhao;//运算符
        fuhao= (int) (random.nextInt(4));
        if(b!=0&&d!=0) {//分母均不为0时生成带有分数的计算题,同时计算结果
        if(fuhao==0) {
            int fenzi=a*d+b*c;
            int fenmu=b*d;
            expArr[0]=biaodashi(a,b)+'+'+biaodashi(c,d)+'=';
            System.out.println(expArr[0]);
            results[i]=reductionofFraction(fenzi, fenmu);
        
        }
        if(fuhao==1&&a*d-b*c>=0) {
            int fenzi=a*d-b*c;
            int fenmu=b*d;
            expArr[0]=biaodashi(a,b)+'-'+biaodashi(c,d)+'=';
            System.out.println(expArr[0]);
            results[i]=reductionofFraction(fenzi, fenmu);
            
        }
        if(fuhao==1&&a*d-b*c<0) {
            int fenzi=b*c-a*d;
            int fenmu=b*d;
            expArr[0]=biaodashi(a,b)+'-'+biaodashi(c,d)+'=';
            System.out.println(expArr[0]);
            results[i]=reductionofFraction(fenzi, fenmu);
            
        }
        if(fuhao==2) {
            int fenzi=a*c;
            int fenmu=b*d;
            expArr[0]=biaodashi(a,b)+'×'+biaodashi(c,d)+'=';
            System.out.println(expArr[0]);
            results[i]=reductionofFraction(fenzi, fenmu);
            
        }
        if(fuhao==3&&c!=0) {
            int fenzi=a*d;
            int fenmu=b*c;
            expArr[0]=biaodashi(a,b)+'÷'+biaodashi(c,d)+'=';
            System.out.println(expArr[0]);
            results[i]=reductionofFraction(fenzi, fenmu);
            
        }
        if(fuhao==3&&c==0) {
            break;
            /*c=1;
            int fenzi=a*d;
            int fenmu=b*c;
            expArr[0]=biaodashi(a,b)+'÷'+biaodashi(c,d)+'=';
            System.out.println(expArr[0]);
            results[i]=reductionofFraction(fenzi, fenmu);*/
            
        }
        
        }
        else {//分母至少一个为0时生成只含有整式的运算式,同时计算结果
            b=1; d=1;
            if(fuhao==0) {
            int fenzi=a*d+b*c;
            int fenmu=b*d;
            expArr[0]=a+"+"+c+"=";
            System.out.println(expArr[0]);
            results[i]=reductionofFraction(fenzi, fenmu);//计算结果
            
        }
        if(fuhao==1&&a*d-b*c>=0) {
            int fenzi=a*d-b*c;
            int fenmu=b*d;
            expArr[0]=a+"-"+c+"=";
            System.out.println(expArr[0]);
            results[i]=reductionofFraction(fenzi, fenmu);//计算结果
            
        }
        if(fuhao==1&&a*d-b*c<0) {
            int fenzi=b*c-a*d;
            int fenmu=b*d;
            expArr[0]=c+"-"+a+"=";
            System.out.println(expArr[0]);
            results[i]=reductionofFraction(fenzi, fenmu);//计算结果
            
        }
        if(fuhao==2) {
            int fenzi=a*c;
            int fenmu=b*d;
            expArr[0]=c+"×"+a+"=";
            System.out.println(expArr[0]);
            results[i]=reductionofFraction(fenzi, fenmu);//计算结果
            
        }
        if(fuhao==3&&c!=0) {
            int fenzi=a*d;
            int fenmu=b*c;
            expArr[0]=a+"÷"+c+"=";
            System.out.println(expArr[0]);
            results[i]=reductionofFraction(fenzi, fenmu);//计算结果
            
        }
        if(fuhao==3&&c==0) {
            break;//排除分母为零的情况
            /*c=1;
            int fenzi=a*d;
            int fenmu=b*c;
            expArr[0]=a+"÷"+c+"=";
            System.out.println(expArr[0]);
            results[i]=reductionofFraction(fenzi, fenmu);*/
            
        }
对分数的处理:
public static String reductionofFraction(int a, int b) {// 结果的分数约分,用于计算结果
        int y = 1;
        for (int i = a; i >= 1; i--) {
            if (a % i == 0 && b % i == 0) {
                y = i;
                break;
            }
        }
        int z = a / y;// 分子
        int m = b / y;// 分母
        if (z == 0) {
            return "0";
        }
        if(m==1) return z+"";
        else  return biaodashi(z,m);
        
    }
    public static String biaodashi(int a,int b) {//判断假分数,并化假分数为带分数
        if(a>=b) {
            int c;
            c=a/b;
            int d;
            d=a%b; 
            {if(d==0) {return c+"";}
            return c+"'"+d+"/"+b;}
        }return a+"/"+b;
    }
生成题目文件及答案文件:
FileWriter fw = null;
    try {
   
        File f=new File("Exersies.txt");//题目写入
        fw = new FileWriter(f, true);
    } catch (IOException e) {
        e.printStackTrace();
    }if(expArr[0]!=null) {
    PrintWriter pw = new PrintWriter(fw);
    pw.println(i+1+"."+expArr[0]);
    pw.flush();
    try {
        fw.flush();
        pw.close();
        fw.close();
    } catch (IOException e) {
        e.printStackTrace();
    }}FileWriter fn = null;
    try {
        
            File f=new File("Answer.txt");//答案写入
            fn = new FileWriter(f, true);
        } catch (IOException e) {
            e.printStackTrace();
        }if(expArr[0]!=null) {
        PrintWriter pn = new PrintWriter(fn);
        pn.println(i+1+"."+results[i]);
        pn.flush();
        try {
            fn.flush();
            pn.close();
            fn.close();
        } catch (IOException e) {
            e.printStackTrace();
        }}
 
统计并输出答题者的情况:
System.out.println("输入ok提交!");//答题完成后输入ok即可提交
     Scanner sc1=new Scanner(System.in);
     String submit=sc1.nextLine();
        if(submit.equals("ok")){
     String array[]=new String[num];
     try
        {   int k=0;
            
            FileReader fr = new FileReader("H://eclipse2//eclipse3//sizeyusuan//Your_answers.txt");
            BufferedReader br = new BufferedReader(fr);
            String s ;
            while((s = br.readLine())!=null) {//读取小学生的答案
                array[k]=s;    k++;
                }br.close();
            fr.close();        
            }catch(IOException e){
                System.out.println("指定文件不存在");
            }
    for(int j=0;j<num;j++){
         if(array[j].equals(results[j])) {//验证答案,统计正确和错误的个数
             
             rightcount[j]=j+1;
             right1++;
         }
         else {
             
             wrongcount[j]=j+1;
             wrong1++;
         }
     }
    FileWriter fg = null;
    try {
        //反馈正确与错误题目的信息
            File f=new File("Grade.txt");
            fg = new FileWriter(f, true);
        } catch (IOException e) {
            e.printStackTrace();
        }
        PrintWriter pg = new PrintWriter(fg);
        pg.println(" ");
        pg.print("Correct:"+right1+"(");
        for (int j = 0; j <= num; j++) {
            if (rightcount[j] != 0) {
                 pg.print(rightcount[j] + ",");
            }
        }
        pg.println(")");
        pg.print("Wrong:"+wrong1+"(");
        for (int j = 0; j <= num; j++) {
            if (wrongcount[j] != 0) {
                 pg.print(wrongcount[j] + ",");
            }
        }
        pg.print(")");
        pg.flush();
        try {
            fg.flush();
            pg.close();
            fg.close();
        } catch (IOException e) {
            e.printStackTrace();
        }}
测试运行
题目文件

答案文件

答题者答案文件

校对文件

项目小结
1.每道题目中出现的运算符个数我们只实现了单个运算符,当我们后来试图扩展多个运算符的时候发现时间不够了,因此只能上交较为简单的版本。
2.查重功能以我们的算法和我们的能力感觉实现有难度,所以并不在我们的计划中。
3.遇到的困难主要是数组越界,通过严谨的检查以及步步验证的方式找出了错误并解决了。另一个须待解决的问题是生成题目的速度有些缓慢,因此完善了多次的算法来提高代码的执行效率。
4.总的来说,在结对编程中我们有各自的想法,通过代码的形式来进行人与人之间的交流不失为一种好的方法,在这个过程中我们培养了团队协作的能力和与他人交际的能力,同时也促使自身的编程能力不断提高,这使我们都受益匪浅。当然如果还有机会的话,我还是希望可以实现带括号的运算式的生成以及答案的计算。
 
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号