问题:
计算税美国联邦个人所得税是根据申请状态和应纳税所得额计算的。有四种申请状态:单身申报人,共同申报的婚姻,单独申报的婚姻和户主。
税率每年变化如下表显示。例如,如果您是应税收入为10,000美元的单身人士,则前8,350美元的税率为10%,其他1,650美元的税率为15%。因此,您的税费是$ 1,082.5。
- 编写一个计算个人所得税的程序,程序应提示用户输入申请状态和应纳税所得额并计算税额。
要求:
输入0表示单身申报者,1表示共同申报,2表示单独申报,3表示户主。您的程序根据申请状态计算应税收入的税额。
对于每种申请状态,都有六个税率。每个税率适用于一定数量的应税收入。例如,单身申报人的40万美元应税收入中,8,350美元的税率为10%,(33,950-8,350)的税率为15%,(82,250-33,950)的税率为25%,(171,550-82,250)的税率为28%,(372,950- 171,550)(33%)和(400,000-372,950)(35%)。
代码实现:
import java.util.Scanner;
public class MyTest {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int status=0;
double tax=0;
String flag="Y";
while(true){
if(flag.equalsIgnoreCase("Y")){
while(true){
System.out.println("请输入您的申请状态(0表示单身申报者/1表示共同申报/2表示单独申报/3表示户主):");
status=sc.nextInt();
if(status==0){
//根据申请状态计算应税收入的税额,将这个需求抽成一个方法
tax=getTax(0);
break;
}else if(status==1){
tax=getTax(1);
break;
}else if(status==2){
tax=getTax(2);
break;
}else if(status==3){
tax=getTax(3);
break;
}else{
System.out.println("输入错误,请重新输入");
}
}
System.out.println("根据计算,您的应税收入的税额为:¥"+tax);
}else if(flag.equalsIgnoreCase("N")){
System.out.println("谢谢使用!");
break;
}else{
System.out.println("输入错误,应该输入Y/N");
}
System.out.println("您还想继续查询吗?(Y/N)");
sc=new Scanner(System.in);
flag=sc.nextLine();
}
}
private static double getTax(int status) {
double income=0;
double tax=0;
while(true){
System.out.println("请输入您的应税收入:(输入的数字不得小于0)");
Scanner sc = new Scanner(System.in);
income=sc.nextDouble();
if(income>0){
switch(status){
case 0:
tax=singleApplicant(income);
return tax;
case 1:
tax=jointFiling(income);
return tax;
case 2:
tax=filedSeparately(income);
return tax;
case 3:
tax=head(income);
return tax;
}
}else{
System.out.println("输入的收入不得低于0¥");
}
}
}
private static double singleApplicant(double income) {
double tax=0;
double one=8350*0.1;//8351<=income<=33950
double tow=(33950-8350)*0.15+one;//33951<=income<=82250
double three=(82250-33950)*0.25+tow;//82251<=income<=171550
double four=(171550-82250)*0.28+three;//171551<=income<=372950
double five=(372950-171550)*0.33+four;//372951<=income
if(income>=0&&income<=8350){
tax= income*0.1;
}else if(income>=8351&&income<=33950){
tax= one+(income-8350)*0.15;
}else if(income>=33951&&income<=82250){
tax= tow+(income-33950)*0.25;
}else if(income>=82251&&income<=171550){
tax= three+(income-82250)*0.28;
}else if(income>=171551&&income<=372950){
tax= four+(income-171550)*0.33;
}else{
tax= five+(income-372950)*0.35;
}
return tax;
}
private static double jointFiling(double income) {
double tax=0;
double one=16700*0.1;//16701<=income<=67900
double tow=(67900-16700)*0.15+one;//67901<=income<=137050
double three=(137050-67900)*0.25+tow;//137051<=income<=208850
double four=(208850-137050)*0.28+three;//208851<=income<=372950
double five=(372950-208850)*0.33+four;//372951<=income
if(income>=0&&income<=16700){
tax= income*0.1;
}else if(income>=16701&&income<=67900){
tax= one+(income-16700)*0.15;
}else if(income>=67901&&income<=137050){
tax= tow+(income-67900)*0.25;
}else if(income>=137051&&income<=208850){
tax= three+(income-137050)*0.28;
}else if(income>=208851&&income<=372950){
tax= four+(income-208850)*0.33;
}else{
tax= five+(income-372950)*0.35;
}
return tax;
}
private static double filedSeparately(double income) {
double tax=0;
double one=8350*0.1;//8351<=income<=33950
double tow=(33950-8350)*0.15+one;//33951<=income<=68525
double three=(68525-33950)*0.25+tow;//68526<=income<=104425
double four=(104425-68525)*0.28+three;//104426<=income<=186475
double five=(186475-105525)*0.33+four;//186476<=income
if(income>=0&&income<=8350){
tax= income*0.1;
}else if(income>=8351&&income<=33950){
tax= one+(income-8350)*0.15;
}else if(income>=33951&&income<=68525){
tax= tow+(income-339550)*0.25;
}else if(income>=68526&&income<=104425){
tax= three+(income-68525)*0.28;
}else if(income>=104426&&income<=186475){
tax= four+(income-104425)*0.33;
}else{
tax= five+(income-186475)*0.35;
}
return tax;
}
private static double head(double income) {
double tax=0;
double one=11950*0.1;//11951<=income<=45500
double tow=(45500-11950)*0.15+one;//45501<=income<=117450
double three=(117450-45500)*0.25+tow;//117451<=income<=190200
double four=(190200-117450)*0.28+three;//190201<=income<=372950
double five=(372950-190200)*0.33+four;//372951<=income
if(income>=0&&income<=11950){
tax= income*0.1;
}else if(income>=11951&&income<=45500){
tax= one+(income-11950)*0.15;
}else if(income>=45501&&income<=117450){
tax= tow+(income-45500)*0.25;
}else if(income>=117451&&income<=190200){
tax= three+(income-117450)*0.28;
}else if(income>=190201&&income<=372950){
tax= four+(income-190200)*0.33;
}else{
tax= five+(income-372950)*0.35;
}
return tax;
}
}
版权声明:本文为weixin_45082647原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。