作业5.2 对5.1内容的完善

   由于两篇博文都在同一电脑上发的原因,造成发布博文的混乱和重复,本来我21林庆光的博客是发布心得体会,而同伴11陈梓仪是发布源代码的。但由于发布问题导致两部分都在我的博客上发,因此请老师移步到我同伴的博客上检查http://home.cnblogs.com/u/chenziyi/。如有不便,敬请原谅!

本周作业是要求我们完善5.1即上星期的作业计算功能的测试和封装,但我和我的搭档11陈梓仪上周都已完成,因此这次作业是对上次的查漏补缺。对一些功能进行完善,以下是具体代码:

public class SS {
    public int add(int a,int b)
    {
        int t=a+b;
        return t;
    }
}

public class SSTest {

    @Test
    public void testAdd() {
        SS t1=new SS();
        int t2=t1.add(9,1);
        assertEquals(10, t2); 
    }

}
加法
package SuanFa;

public class SS {
    public int jian(int a,int b)
    {
        int t=a-b;
        return t;
    }
}



public void testAdd() {
        SS t1=new SS();
        int t2=t1.jian(9,1);
        assertEquals(8, t2); 
    }
减法
public int cheng(int a,int b)
    {
        int t=a*b;
        return t;
    }


public void testcheng() {
        SS t1=new SS();
        int t2=t1.cheng(9,1);
        assertEquals(9, t2); 
    }
public int chu(int a,int b)
    {
        int t=0;
        if(b==0)
        {
            System.out.println("分母不可以为0");
        }
        else
        {
            t=a/b;
            
        }
        return t;
        
    }


public void testchu() {
        SS t1=new SS();
        int t2=t1.chu(9,1);
        assertEquals(9, t2); 
    }
除法

同伴地址:http://home.cnblogs.com/u/guangge/

posted @ 2015-05-08 18:59  21林庆光  阅读(112)  评论(1编辑  收藏  举报