结对项目

结对项目:四则运算

吴文俊 学号:3119005345

梁志鹏 学号:3119005328

这个作业属于哪个课程
点击跳转_网工1934-软件工程
这个作业要求在哪里
点击跳转_作业要求
这个作业的目标 通过两人合作,合理分工,完成结对项目的四则运算设计

一、GitHub地址

点击跳转_GitHub个人项目

二、P2P2.1

PSP2.1 Personal Software
Process Stages
预估耗时(分钟) 实际耗时(分钟)
Planning 计划 25 15
· Estimate · 估计这个任务需要多少时间 20 20
Development 开发 1465 1105
· Analysis · 需求分析 (包括学习新技术) 240 300
· Design Spec · 生成设计文档 60 60
· Design Review · 设计复审 60 40
· Coding Standard · 代码规范 (为目前的开发制定合适的规范) 60 40
· Design · 具体设计 300 240
· Coding · 具体编码 240 300
· Code Review · 代码复审 60 30
· Test · 测试(自我测试,修改代码,提交修改) 120 60
Reporting 报告 80 100
· Test Repor · 测试报告 100 60
· Size Measurement · 计算工作量 40 30
· Postmortem
Process Improvement Plan
事后总结, 并提出过程改进计划 60 30
· 合计 1465 1105

三、部分代码及解析

随机为分子分母赋值

int a= (int) (random.nextInt(valueSize));//分子
int b= (int) (random.nextInt(valueSize));//分母
int c= (int) (random.nextInt(valueSize));//另一个分子
int d= (int) (random.nextInt(valueSize));//另一个分母

采用0123指代运算符加减乘除

int operator;//运算符
            operator= (int) (random.nextInt(4));
            if(b!=0&&d!=0) {//分母均不为0时生成带有分数的计算题,同时计算结果
                if(operator==0) {
                    ```
                }
                if(operator==1&&a*d-b*c>=0) {
                   ```
                }
                if(operator==1&&a*d-b*c<0) {
                  ```
                }
                if(operator==2) {
                ```           
                }
                if(operator==3&&c!=0) {
                ```
                }
                if(operator==3&&c==0) {
                    break;
                }

            }

对分数处理--约分

   // 分数约分,用于计算结果
public static String aboutPoints(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 inspect(z,m);

    }

对分数处理--化假分数为带分数

    //判断假分数,并化假分数为带分数
    public static String inspect(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(subject[0]!=null) {
                PrintWriter pw = new PrintWriter(fw);
                pw.println(i+1+"."+subject[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(subject[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();
                }
            }

最后输出即可

String array[]=new String[number];
            try
            {   int k=0;

                FileReader fr = new FileReader("E:\\Study\\IDEA_code\\结对项目\\Answer.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("指定文件不存在");
            }
```

四、运行结果展示


posted @ 2021-10-25 23:25  橘子皮WuFan  阅读(27)  评论(0编辑  收藏  举报