作业5.2

package Test;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
public class sizeyunsuan {
    public static void main(String[] args) {
        String condition = "";
        int x,y;
        String z ,p,p1;
        Scanner inr = new Scanner(System.in);
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in)) ;
       do{ 
        System.out.print("请输入第一个数字:") ;
        while(true)
        {
            try
            {
                p=in.readLine();
               
                x=Integer.parseInt(p);
                if(x>-1000||x<1000)
                {
                    System.out.println("\n") ;
                }
                break;
            }
            catch(Exception e)
            {
                System.out.println("\n错误") ;
            }
        }
        
        System.out.print("请输入第二个数字:") ;
        while(true)
        {
            
            try
            {
                p1=in.readLine();
                
                y=Integer.parseInt(p1);
                if(y>-1000||y<1000)
                {
                    System.out.println("\n") ;
                }
                break;
            }
            catch(Exception e)
            {
                System.out.println("\n错误") ;
            }
        }
        
        System.out.println("请输入运算符(+,-,*,/):");
        z = inr.nextLine();    
        
        
        System.out.println("\n"+x+" "+z+" "+y+"=");
        core test = new core();
        test.yunsuan(z, x, y);
        System.out.print("是否继续?Y:继续,任意字符:结束");
        condition = inr.nextLine();
    }while("Y".equals(condition));
    }
}
package Test;

public class core {
    public void yunsuan(String cc, double a, double b) {
         js test1 = new js();
     if (cc.equals("+")) {
         
         
         test1.jia(a , b);
            } 
     else if (cc.equals("-")) {
         
         test1.jian(a , b);
         
         }
     else if (cc.equals("*")) {

         test1.cheng(a , b);
         
             }
     else if (cc.equals("/")) {
         
                if (b != 0) {
                    test1.chu(a , b);
                    
                 } 
                else {
                 System.out.println("被除数不能为0!");
                 throw new ArithmeticException();
            }
         } 
     else {
             System.out.println("运算符不符合!");
         }
    }
}
package Test;

public class js {

    /**
     * @param args
     */
     public static  double jia( double a, double b) {
         double result=0;
         result=a+b;
         System.out.println(a +"+"+ b);
         System.out.println(result);
        return result;
     }
     
     
     public static  double jian( double a, double b) {
         double result=0;
         result=a-b;
         System.out.println(a +"-"+ b);
         System.out.println(result);
        return result;
     }
     
     
     public static  double cheng( double a, double b) {
         double result=0;
         result=a*b;
         System.out.println(a +"*"+ b);
         System.out.println(result);
        return result;
     }
     
     
     public static  double chu( double a, double b) {
         double result=0;
         result=a/b;
         System.out.println(a +"/"+ b);
         System.out.println(result);
        return result;
     }
}

package Test;

import static org.junit.Assert.*;

import org.junit.Test;

public class jsTest {

    @Test
    
        public void testJia1() {
            double a;
            js test2=new js();
            a=js.jia(5,2);
        }

        @Test
        public void testJian1() {
            double b;
            js test2=new js();
            b=js.jian(10,1);
        }

        @Test
        public void testChen1() {
            double c;
            js test2=new js();
            c=js.cheng(8,3);
        }

        @Test
        public void testChu1() {
            double d;
            js test2=new js();
            d=js.chu(6,2);
        }

}

 

我的小伙伴 06刘泽豪  http://www.cnblogs.com/wsnd/

posted @ 2015-05-08 18:13  10易华生  阅读(135)  评论(1编辑  收藏  举报