我正在尝试获取有关我正在创建的用于计算税款的JavaScript的帮助。感觉我的数学有问题,但是我认为代码按预期工作。当我输入2个值时,得出的数学值似乎并不准确。如果有人可以看一下,看看我的工作出了什么问题,那将不胜感激。
package taxableIncome;
import java.util.Scanner;
public class taxableIncome {
public static void main(String[] args) {
System.out.println("Enter filing status: ");
Scanner input = new Scanner(System.in);
double x = input.nextDouble();
if (x == 0) {
x = 'S';
} else if (x == 1) {
x = 'M';
} else if (x == 2) {
x = 'J';
} else if (x == 3) {
x = 'H';
}
System.out.println("Enter taxable income: ");
input = new Scanner(System.in);
double y = input.nextInt();
if (x == 'S') {
if (y <= 8350) {
System.out.println(y*.01);
} else if (y >= 8351 && y<= 33950) {
System.out.println(y*.15);
} else if (y >= 33951 && y<= 82250) {
System.out.println(y*.25);
} else if (y >= 82251 && y<= 171550) {
System.out.println(y*.28);
} else if (y >= 171551 && y<= 372950) {
System.out.println(y*.33);
} else System.out.println(y*.35);
}
if (x == 'M') {
if (y <= 8350) {
System.out.println(y*.01);
} else if (y >= 8351 && y<= 33950) {
System.out.println(y*.15);
} else if (y >= 33951 && y<= 68525) {
System.out.println(y*.25);
} else if (y >= 68526 && y<= 104425) {
System.out.println(y*.28);
} else if (y >= 104426 && y<= 186475) {
System.out.println(y*.33);
} else System.out.println(y*.35);
}
if (x == 'J') {
if (y <= 16700) {
System.out.println(y*.01);
} else if (y >= 16701 && y<= 67900) {
System.out.println(y*.15);
} else if (y >= 67901 && y<= 137050) {
System.out.println(y*.25);
} else if (y >= 137051 && y<= 208850) {
System.out.println(y*.28);
} else if (y >= 208851 && y<= 372950) {
System.out.println(y*.33);
} else System.out.println(y*.35);
}
if (x == 'H') {
if (y <= 11950) {
System.out.println(y*.01);
} else if (y >= 11951 && y<= 45500) {
System.out.println(y*.15);
} else if (y >= 45501 && y<= 117450) {
System.out.println(y*.25);
} else if (y >= 117451 && y<= 190200) {
System.out.println(y*.28);
} else if (y >= 190201 && y<= 372590) {
System.out.println(y*.33);
} else System.out.println(y*.35);
}
}
}
答案 0 :(得分:1)
public class taxableIncome {
public static void main(String[] args) {
System.out.println("Enter filing status (S,M,J,H): ");
Scanner input = new Scanner(System.in);
char status = input.nextLine().toUpperCase().charAt(0);
System.out.println("Enter taxable income: ");
input = new Scanner(System.in);
double taxableIncome = input.nextDouble();
if (status == 'S') {
if (taxableIncome <= 8350) {
System.out.println(taxableIncome * .01);
} else if (taxableIncome >= 8351 && taxableIncome <= 33950) {
System.out.println(taxableIncome * .15);
} else if (taxableIncome >= 33951 && taxableIncome <= 82250) {
System.out.println(taxableIncome * .25);
} else if (taxableIncome >= 82251 && taxableIncome <= 171550) {
System.out.println(taxableIncome * .28);
} else if (taxableIncome >= 171551 && taxableIncome <= 372950) {
System.out.println(taxableIncome * .33);
} else
System.out.println(taxableIncome * .35);
}
if (status == 'M') {
if (taxableIncome <= 8350) {
System.out.println(taxableIncome * .01);
} else if (taxableIncome >= 8351 && taxableIncome <= 33950) {
System.out.println(taxableIncome * .15);
} else if (taxableIncome >= 33951 && taxableIncome <= 68525) {
System.out.println(taxableIncome * .25);
} else if (taxableIncome >= 68526 && taxableIncome <= 104425) {
System.out.println(taxableIncome * .28);
} else if (taxableIncome >= 104426 && taxableIncome <= 186475) {
System.out.println(taxableIncome * .33);
} else
System.out.println(taxableIncome * .35);
}
if (status == 'J') {
if (taxableIncome <= 16700) {
System.out.println(taxableIncome * .01);
} else if (taxableIncome >= 16701 && taxableIncome <= 67900) {
System.out.println(taxableIncome * .15);
} else if (taxableIncome >= 67901 && taxableIncome <= 137050) {
System.out.println(taxableIncome * .25);
} else if (taxableIncome >= 137051 && taxableIncome <= 208850) {
System.out.println(taxableIncome * .28);
} else if (taxableIncome >= 208851 && taxableIncome <= 372950) {
System.out.println(taxableIncome * .33);
} else
System.out.println(taxableIncome * .35);
}
if (status == 'H') {
if (taxableIncome <= 11950) {
System.out.println(taxableIncome * .01);
} else if (taxableIncome >= 11951 && taxableIncome <= 45500) {
System.out.println(taxableIncome * .15);
} else if (taxableIncome >= 45501 && taxableIncome <= 117450) {
System.out.println(taxableIncome * .25);
} else if (taxableIncome >= 117451 && taxableIncome <= 190200) {
System.out.println(taxableIncome * .28);
} else if (taxableIncome >= 190201 && taxableIncome <= 372590) {
System.out.println(taxableIncome * .33);
} else
System.out.println(taxableIncome * .35);
}
}
}