zoukankan      html  css  js  c++  java
  • 封装更新

    import static org.junit.Assert.*;
    
    import org.junit.Test;
    
    
    public class FZTest {
    
        int z;
        @Test
        public void testJia() {
            FZ fz = new FZ();
            z = fz.jia(3, 1);
            assertEquals(4,z);
        }
        @Test(expected=ArithmeticException.class)
        public void testchu() {
            double b;
            FZ fz = new FZ();
            b = fz.Chu(3, 0);
            
        }
        @Test
        public void testjian() {
            
            FZ fz = new FZ();
            z = fz.jian(3, 0);
            assertEquals(3,z);
            
        }
        @Test
        public void testCheng() {
            
            FZ fz = new FZ();
            z = fz.Cheng(3, 0);
            assertEquals(0,z);
            
        }
    
    
    }

    抛出异常后

    import java.util.Random;
    
    
    public class FZ {
        private int a;
        private int b;
        int c;
        public int  jia(int a,int b)
        {
        
            System.out.println(""+a);
            System.out.println(""+b);
            c = a+b;
            System.out.println("a+"+"b"+"="+(a+b+"\n"));
            return c;
            
        }
        public int  jian(int a,int b)
        {
            
            System.out.println(""+a);
            System.out.println(""+b);
            c=a-b;
            System.out.println("a-"+"b"+"="+(a-b)+"\n");
            return c;
            
            
        }
        public int Cheng(int a,int b)
        {   
            System.out.println(""+a);
            System.out.println(""+b);
            c=a*b;
            System.out.println("a*"+"b"+"="+(a*b)+"\n");
            return c;
        }
        public double  Chu(int a,int b)
        {
            double c;
            c=(double) (Math.round((a/b)*100/100.0));
            System.out.println(""+a);
            System.out.println(""+b);
            if(b!=0)
                System.out.println("c=a/b="+(c)+"\n");
            else
                throw new ArithmeticException();
                System.out.println("分母不能为0!");
                  
                return c;
        }
    
        /**
         * @param args
         */
        public static void main(String[] args) {
            // TODO Auto-generated method stub
             FZ Jia=new FZ();
             Jia.jia(5, 3);
             FZ Jian=new FZ();
             Jian.jian(6,2);
             FZ cheng=new FZ();
             cheng.Cheng(6,5);
             FZ chu=new FZ();
             chu.Chu(3,0);
             
        }
    
    }
  • 相关阅读:
    [翻译] GCDObjC
    [翻译] ValueTrackingSlider
    [翻译] SWTableViewCell
    使用 NSPropertyListSerialization 持久化字典与数组
    [翻译] AsyncImageView 异步下载图片
    KVC中setValuesForKeysWithDictionary:
    [翻译] Working with NSURLSession: AFNetworking 2.0
    数据库引擎
    什么是数据库引擎
    网站添加百度分享按钮代码实例
  • 原文地址:https://www.cnblogs.com/xukan123/p/4488340.html
Copyright © 2011-2022 走看看