面向对象的第一次pta作业第一题:计算税率

import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
        Scanner tax = new Scanner(System.in);
        
        int taxStatus;
        float taxMoney;
        taxStatus=tax.nextInt();
        taxMoney=tax.nextFloat();
        
        if(taxMoney<0) {
            System.out.println("Wrong Format");
            System.exit(0);
        }
        
        jisuan(taxStatus,taxMoney);
        
        
    }
    public static void jisuan(int a,float b) {
        double c=0;
        switch (a) {
        case 0:
            if (b<=8350)
                c=b*0.1;
            else if (b<=33950) 
                c=8350*0.1+(b-8350)*0.15;
            else if (b<=82250)
                c=8350*0.1+(33950-8350)*0.15+(b-33950)*0.25;
            else if (b<=171550)
                c=8350*0.1+(33950-8350)*0.15+(82250-33950)*0.25+(b-82250)*0.28;
            else if (b<=372950)
                c=8350*0.1+(33950-8350)*0.15+(82250-33950)*0.25+(171550-82250)*0.28+(b-171550)*0.33;
            else 
                c=8350*0.1+(33950-8350)*0.15+(82250-33950)*0.25+(171550-82250)*0.28+(372950-171550)*0.33+(b-372950)*0.35;
            break;
        case 1:
            if (b<=16700)
                c=b*0.1;
            else if (b<=67900) 
                c=16700*0.1+(b-16700)*0.15;
            else if (b<=137050)
                c=16700*0.1+(67900-16700)*0.15+(b-67900)*0.25;
            else if (b<=208850)
                c=16700*0.1+(67900-16700)*0.15+(137050-67900)*0.25+(b-137050)*0.28;
            else if (b<=372950)
                c=16700*0.1+(67900-16700)*0.15+(137050-67900)*0.25+(208850-137050)*0.28+(b-208850)*0.33;
            else 
                c=16700*0.1+(67900-16700)*0.15+(137050-67900)*0.25+(208850-137050)*0.28+(372950-208850)*0.33+(b-372950)*0.35;
            break;
        case 2:
            if (b<=8350)
                c=b*0.1;
            else if (b<=33950) 
                c=8350*0.1+(b-8350)*0.15;
            else if (b<=68525)
                c=8350*0.1+(33950-8350)*0.15+(b-33950)*0.25;
            else if (b<=104425)
                c=8350*0.1+(33950-8350)*0.15+(68525-33950)*0.25+(b-68525)*0.28;
            else if (b<=186475)
                c=8350*0.1+(33950-8350)*0.15+(68525-33950)*0.25+(104425-68525)*0.28+(b-104425)*0.33;
            else 
                c=8350*0.1+(33950-8350)*0.15+(68525-33950)*0.25+(104425-68525)*0.28+(186475-104425)*0.33+(b-186475)*0.35;
            break;
        case 3:
            if (b<=11950)
                c=b*0.1;
            else if (b<=45500) 
                c=11950*0.1+(b-11950)*0.15;
            else if (b<=117450)
                c=11950*0.1+(45500-11950)*0.15+(b-45500)*0.25;
            else if (b<=190200)
                c=11950*0.1+(45500-11950)*0.15+(117450-45500)*0.25+(b-117450)*0.28;
            else if (b<=372950)
                c=11950*0.1+(45500-11950)*0.15+(117450-45500)*0.25+(190200-117450)*0.28+(b-190200)*0.33;
            else 
                c=11950*0.1+(45500-11950)*0.15+(117450-45500)*0.25+(190200-117450)*0.28+(372950-190200)*0.33+(b-186475)*0.35;
            break;

        default:
            System.out.println("Wrong Format");
            System.exit(0);
            break;
        }
        System.out.println(c);
    }

}

 

 

 

说实话我觉得做这道题的时候并没有感觉到c语言和Java的区别,而且题目繁杂且无聊,有点不明白面向对象为什么要叫面向对象

posted on 2020-04-08 20:52  xyx's  阅读(210)  评论(0编辑  收藏  举报

导航