実験四-ユニットテスト

10534 ワード

import java.util.*;
public class jisuan {
    public static void main(String[] args) {
        System.out.println(" :+,-,*,/");
        Scanner sc=new Scanner(System.in);
        System.out.println(" :");
        String str=sc.nextLine();
        System.out.println(" :");
        String str2=sc.nextLine();
        System.out.println(" :");
        String str3=sc.nextLine();
        try{
        double a=Double.parseDouble(str);
        double b=Double.parseDouble(str2);
        Core core=new Core();
        core.fengzhuan(str3, a, b);
        }catch(NumberFormatException e){
            System.out.println("");
            Core core= new Core();
            System.out.println(" :");
            String str4=sc.nextLine();
            System.out.println(" :");
            String str5=sc.nextLine();
            double a=Double.parseDouble(str4);
            double b=Double.parseDouble(str5);
            core.fengzhuan(str3, a, b);
        }
        finally{}
    }
}
class Core {
    Scanner g=new Scanner(System.in);
    public void fengzhuan(String op,double a,double b){
        if(op.equals("+")){
            System.out.println(a+b);
        }else if(op.equals("-")){
            System.out.println(a-b);
        }else if(op.equals("*")){
            System.out.println(a*b);
        }else if(op.equals("/")){
            if(b==0){
                System.out.println(" ");
                System.out.println(" b :");
                b=g.nextDouble();
                System.out.println(a/b);
            }
            else if(b!=0){
                System.out.println(a/b);
            }
            }
        else{
            String str3;
            System.out.println("");
            str3=g.next();
             jisuan2 ji=new jisuan2(); 
             ji.huansuan(str3, a, b);
        }
    }
}
class jisuan2 extends jisuan{
    Scanner sc=new Scanner(System.in);
    public void huansuan(String str3,double a,double b){
        if(str3.equals("+")){
            System.out.println(a+b);
        }else if(str3.equals("-")){
            System.out.println(a-b);
        }else if(str3.equals("*")){
            System.out.println(a*b);
        }else if(str3.equals("/")){
            if(b==0){
                System.out.println(" ");
                System.out.println(" b :");
                b=sc.nextDouble();
                System.out.println(a/b);
            }
            else if(b!=0){
                System.out.println(a/b);
            }
            }
    }
    
}