软工网络15结对编程练习

一、链接

结对编程成员博客园地址:

201521123009 徐璐琳 博客园地址:http://www.cnblogs.com/abonxxxu/ 码云地址:https://gitee.com/abonxxxu/events
201521123028 李家俊 博客园地址:http://www.cnblogs.com/KILL-ljj/ 码云地址:https://gitee.com/Forgetaboutj/events

结对编程码云地址:https://gitee.com/abonxxxu/software_engineering__pair_programming
代码上传截图:

照片:

源代码:https://git.coding.net/qwx_hh/java-szys.git

二、代码

1.需求分析:

源代码的基本功能和设计思路如上图 ,在功能上,源代码的核心模块是Arithmetic(),也就是计算模块,除此之外,源代码中还有Work_Time(计时功能模块),History(历史题目存取模块),Frame(图形界面模块),QAlist(实现问题和答案的模块)
为了实现新的需求,我们需要在代码上实现三个主要的功能:
①重复运算内容检测
②实现括号和多运算符运算,实现复合运算
③实现乘方运算

2.程序设计:

由于主要是实现计算上的功能,因此我们在Arithmetic.java(用于实现运算的模块)上做出修改,以实现需求分析中预计的功能)

3.代码展示:
对于加减乘除+乘方基本算法(整数):

    public String int_operation()
    {
        int result = 0;
        if(a==0)
            result=f+g;
        if(a==1)
            result=f-g;
        if(a==2)
            result=f*g;
        for(int i = 0; i <= flage; i++)//查询num3中有没有与result相同的元素
        {
            if(result == num3[i])
                return null;//如果有相同的返回null
        }
        num3[flage++] = result;//如果没有相同的就把新的result的值放入num3中
        astr = String.valueOf( result);
        if(a==3)
        {
            if(g==0)
            {
                astr=int_operation();
                return astr;
            }
            else
            {
                if(g!=0&&g!=1){
                    int d=common_divisor(f,g);
                    f=f/d;
                    g=g/d;
                    astr = (f+"/"+g);
                }
                if(g==1)
                    astr=(""+f);
            }
            
        }
        if(a==4)
        {
            result=(int) Math.pow(f, g);
        }
        return astr;
    }

对于加减乘除+乘方基本算法(分数):

    public String fra_operation(){
        this.b = new Random().nextInt(10)%(10-1+1) + 1;
        this.c = new Random().nextInt(10)%(10-2+1) + 2;
        this.d = new Random().nextInt(10)%(10-1+1) + 1;
        this.e = new Random().nextInt(10)%(10-2+1) + 2;
        if(c<b||e<d||c%b==0||e%d==0)
        {
            astr=fra_operation();
            return astr;
        }
            
        int fz=1,fm=c*e;
        if(a==0)
            fz=b*e+c*d;
        if(a==1){
            fz=b*e-c*d;
            if(fz==0)
            {
                return astr=("0");
            }
        }
            
        if(a==2)
            fz=b*d;
        if(a==3)
        {
            fz=b*e;
            fm=c*d;
        }
        int f=common_divisor(fm,fz);
        if(f>0){
            fm=fm/f;
            fz=fz/f;
        }
        if(f<0){
            fm=-fm/f;
            fz=-fz/f;
        }
        if(a==4)
        {
            fz=(int) Math.pow(b*e, f);
            fm=(int) Math.pow(c*d, f);
            
        }
        astr = (fz+"/"+fm);
        return astr;
        
    }

对于分数中最大公约数的处理:

    public static int common_divisor(int m,int n)
    {
        while(m%n!=0){
            int t=m%n;
            m=n;
            n=t;
        }
        return n;
    }
对于计时函数:
public class Work_Time extends TimerTask{

    static int y=0;
    static int z=0;
    @Override
    public void run() {
        // TODO Auto-generated method stub
        String str_second = Frame.Time.getText().substring(6);
        int x = Integer.parseInt(str_second);
        if(Frame.Time.getText().equals("00:00.00")){
            x=0;y=0;z=0;
        }
        x++;
        if(z<10){
            if(y<10)
            {
                if(x<100)
                    Frame.Time.setText("0"+z+":0"+y+"."+x);
                if(x==100)
                {
                    y++;
                    Frame.Time.setText("0"+z+":0"+y+".0");
                    x=0;
                    
                }
            }
            if(y<60&&y>=10)
            {
                if(x<100)
                    Frame.Time.setText("0"+z+":"+y+"."+x);
                if(x==100)
                {
                    y++;
                    Frame.Time.setText("0"+z+":"+y+".0");
                    x=0;
                    
                }
            }
            if(y==60){
                y=0;
                x=0;
                z++;
            }
        }
        if(z<60&&z>=10){
            if(y<10)
            {
                if(x<100)
                    Frame.Time.setText(z+":0"+y+"."+x);
                if(x==100)
                {
                    y++;
                    Frame.Time.setText(z+":0"+y+".0");
                    x=0;
                    
                }
            }
            if(y<60&&y>=10)
            {
                if(x<100)
                    Frame.Time.setText(z+":"+y+"."+x);
                if(x==100)
                {
                    y++;
                    Frame.Time.setText(z+":"+y+".0");
                    x=0;
                    
                }
            }
            if(y==60){
                y=0;
                x=0;
                z++;
            }
            else
            {
                Frame.Time.setText("超过一小时了,偶尔放弃也不是坏事呢。");
            }
        }
    }
    

}

对于减少重复题目(主要代码):

int [][] num2 = new int[10][4];
int [][] num1 = new int[10][2];
int [] num3 = new int [10];//保存每道题的结果
int flage = 0;//记录num3数组中的元素个数
int flage2 = 0;//保存整数数组num1中的个数
int flage3= 0;//保存分数数组num2的个数
·
·
·
    public String toString(){
        if(x==true){
            //先判断在num1里面有没有相同的元素
            for(int i = 0; i <= flage2; i++)
            {
                if((f == num1[i][0] && g == num1[i][1]) || (f == num1[i][0] || g == num1[i][1]))
                    return null;
            }
            //如果没有就把原来的值放入
            num1[flage2++][0] = f;
            num1[flage][1] = g;
            
            if(a==0)
                qstr=(f+"+"+g+"=");
            if(a==1)
                qstr=(f+"-"+g+"=");
            if(a==2)
                qstr=(f+"*"+g+"=");
            if(a==3)
                qstr=(f+"/"+g+"=");
            if(a==3)
                qstr=(f+"/"+g+"=");
            if(a==4)
                qstr=(f+"^"+g+"=");
        }
        if(x==false){
            //先判断在num2里面有没有分数运算相同的元素
            for(int i = 0; i <= flage3; i++)
            {
                if((b == num2[i][0] && c == num2[i][1] && d == num2[i][2] && e == num2[i][3]) || (b == num2[i][2] && c == num2[i][3] && d == num2[i][0] && e == num2[i][1]))
                    return null;
            }
            //如果没有就把原来的值放入
            num2[flage3++][0] = b;
            num2[flage3][1] = c;
            num2[flage3][2] = d;
            num2[flage3][3] = e;
            if(a==0)
                qstr=(b+"/"+c+"+"+d+"/"+e+"=");
            if(a==1)
                qstr=(b+"/"+c+"-"+d+"/"+e+"=");
            if(a==2)
                qstr=(b+"/"+c+"*"+d+"/"+e+"=");
            if(a==3)
                qstr=(b+"/"+c+"/"+d+"/"+e+"=");
            if(a==4)
                qstr=(b+"/"+c+"^"+d+"/"+e+"=");
        }
        return qstr;
    }

4.程序运行:


乘方功能:

单元测试:

重复率测试:

HTML:

CHECKSTYLE:

效能测试:



5.小结感受:

这一次结对编程对于没什么编程水平的我来说感觉很难受,在第一次看代码的时候,还有跟我的编程搭档徐同学合作的时候,我甚至有很多听不懂、看不懂的地方,于是我把源代码的代码规范作为我的切入点,慢慢的了解到了这个程序的构造,以及我看不懂的地方究竟是做什么用的,慢慢的我就对程序有所了解,最后在设计脑图和需求分析的时候也起到很大的作用。所以也十分感谢我耐心勤劳的搭档徐同学带我飞=-=,同时也感谢念学长的优质程序,思路清晰,让我在看的时候很快就能看懂。

这次的结对编程,让我切身找到了一种在做项目的感觉(虽然做出来的也不是什么大东西),我认为要想合作做好一个项目(程序),首先建立在分工明确的情况下,各司其职,然后要有不断的交流,这样可以大幅减少配合上的失误,也避免了在完成的过程中产生矛盾。在项目的大体思路上,我们先是在源代码上进行分析→找出优缺点,发现逻辑泥球→对代码进行改进,简化代码→不断测试,再次改进→做总结,完成PSP等。

PSP:

posted @ 2018-03-22 14:58  forgetaboutJ  阅读(180)  评论(0编辑  收藏  举报