작업 5(강화판)

2866 단어 숙제
package com.szys.junit;

 

 

public class Packaging {

    int m;

    int n;

    public T(int m,int n)

    {

    	try{

        this.m=m;

        this.n=n;

    	}catch(Exception e)

    	{

    		if(a<0||a>100||b<0||b>100)

    		{

    			System.out.ptintln("          !");

    		}

                

    	}

    }

    public int add()

    {

        return m + n;

    }

    public int minus()

    {

        return m - n;

    }

    public int mul()

    {

        return m * n;

    }

    public int div()throws Exception

    {

        if(0 == n)

        {

            throw new Exception("     0");           

        }

        return m / n;

 

    }

}
package com.szys.junit.test;



import static org.junit.Assert.*;

 

import org.junit.Test;

 

import com.szys.junit.T;

 

public class Test {

 

    public void test() {

        int m=new T(1, 2).add();

        assertEquals(3, m);

        int n=new T(4, 3).minus();

        assertEquals(1,n);

        int x=new T(3, 4).mul();

        assertEquals(12,x);

        try {

        int y=new T(4, 4).div();

        assertEquals(1, y);

        }catch(Exception e){

            e.printStackTrace();

        }

    }

 

}

try-catch 문구를 추가했습니다.단원 테스트는 아직 잘 몰라요. 향상이 필요해요!

좋은 웹페이지 즐겨찾기