5.1四則演算ユニットテストj


先週休みを取って授業を休んだので、今週帰ってきてやっと宿題を知って、時間は比較的に急いで、個人の能力はまた不足して、宿題の質はあまりよくありません
Calculator.java







import java.util.Scanner;





public class Calculator {

    public static void main(String[] args) {

        int test(int n)

{

    int ranswer=0;            

    int uanswer=0;            

    int t=0;                

    char operation;            

    int num1=0;                

    int num2=0;                







    switch(n)

    {

        case 1:

            operation='+';

            break;



        case 2:

            operation='-';

            break;



        case 3:

            operation='*';

            break;



        case 4:

            operation='/';

            break;

    }





    if((operation=='-') && (num1<num2))

    {

        t=num1;

        num1=num2;

        num2=t;

    }





    if(operation=='/')

    {

        if(num2==0)

        {

            num2=1;

        }

        num1=num1*num2;            

    }



    printf("%d%c%d= ",num1,operation,num2);

    scanf("%d",&uanswer);





    switch(operation)

    {

        case '+':

        ranswer=num1+num2;

        break;



        case '-':

        ranswer=num1-num2;

        break;



        case '*':

        ranswer=num1*num2;

        break;



        case '/':

        ranswer=num1/num2;

        break;

    }

        

        Core core = new Core();

        core.calc(n, num1, num2);

    }

}

Core.java





public class Core {

    public void calc(String n, double num1, double num2) {

        if (n.equals("1")) {

            System.out.println(num1 + num2);

        } else if (n.equals("2")) {

            System.out.println(num1 - num2);

        } else if (n.equals("3")) {

            System.out.println(num1 * num2);

        } else if (n.equals("4")) {

            if (num2!= 0) {

                System.out.println(num1 / num2);

            } else {

                System.out.println("");

            }

        } else {

            System.out.println("");

        }

    }

}