简体   繁体   English

IF 语句没有打印正确的数字?

[英]IF statement not printing correct numbers?

I am creating a simple tax bracket application in Java for a homework project.我正在用 Java 为家庭作业项目创建一个简单的税级应用程序。

It takes the gross income, subtracts how many exemptions the user has and as well subtracts standard deductions for a total that equals the taxable income, which puts it in the tax bracket and does the calculation to tell the user their tax due.它采用总收入,减去用户拥有的免税数量,并减去标准扣除额,得出等于应税收入的总额,将其置于税级中,并进行计算以告知用户应缴税款。

I have it the taxable and taxrate set up in IF statements that should do the proper calculation for the tax due, but its almost completely doubling the value.我在 IF 报表中设置了应纳税额和税率,应该正确计算应缴税款,但它几乎完全使价值翻了一番。

The IF statements are: IF 语句是:

if (taxable >= 1 && taxable <= 9075){
        taxrate = (int) (taxable * .10);
    } else if (taxable >= 9076 && taxable <= 36900) {
        taxrate = (int) (taxable * .15)  + 908;
    } else if (taxable >= 36901 && taxable <= 89350) {
        taxrate = (int) (taxable * .25)  + 5082;
    } else if (taxable >= 89351 && taxable <= 186350){
        taxrate = (int) (taxable * .28) + 18195;
    } else if (taxable >= 186351 && taxable <= 405100){
        taxrate = (int) (taxable * .33) + 45354;
    } else if (taxable >= 405101 && taxable <= 406750) {
        taxrate = (int) (taxable * .35) + 117541;
    } else if (taxable >= 406751) {
        taxrate = (int) (taxable * .396) +118119;
    }

The random add of numbers at the ends are the previous tax brackets tax due, which adds it to the next bracket and so on.末尾随机添加的数字是前一个税级应缴税款,将其添加到下一个税级,依此类推。 I know it's probably a very simple mistake, so do any of the Java experts have a solution?我知道这可能是一个非常简单的错误,所以有没有 Java 专家有解决方案?

Also, the code for taxable is:此外,应税代码是:

static int taxable = gross - exempt - standard;静态 int 应税 = 总额 - 免税 - 标准;

gross could equal any number, same with exempt and standard毛额可以等于任何数字,与豁免和标准相同

I think the general formula to calculate the taxes for a given income range ( rangemin , rangemax ) should be:我认为计算给定收入范围( rangeminrangemax )的税收的一般公式应该是:

taxrate = (taxable - rangemin) * rangePerc + rangemin * previousRangePerc

So that, in your code:所以,在你的代码中:

if (taxable >= 1 && taxable <= 9075){
        taxrate = (int) (taxable * .10);
} else if (taxable >= 9076 && taxable <= 36900) {
        taxrate = (int) ((taxable - 9076) * .15)  + 908;
} else if (taxable >= 36901 && taxable <= 89350) {
    taxrate = (int) ((taxable - 36901) * .25)  + 5082;
} ... 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM