java - 关于我的 JavaScript 税务问题的问题
问题描述
我正在尝试就我正在创建的用于计算税收的 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);
}
}
}
解决方案
- 我更改输出以向用户提示他可以输入的内容。
- 而不是读取双重更改它以存储第一个字符,因为那是您用来确定状态的内容。
- 重命名了您的 x 和 y,因为我不记得所有 x 和 y 的含义。
- 从用户输入中读取 double 而不是 int。
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);
}
}
}
推荐阅读
- flutter - 一旦我有响应,未来的建设者就不会更新
- node.js - 使用 Axios 和 Express 未定义响应
- ios - 从过期的 iOS 开发人员安装的应用程序中恢复数据?
- matlab - 在 Emacs Org-mode Win10 中运行 Matlab
- dask - Dask:如何将延迟函数与工作资源一起使用?
- javascript - 如何将其转换为 es6 箭头函数?在香草 JS
- visual-studio-code - vscode remote-ssh 启动可能吗?
- python - 如何在测试文件中从未明确存在的对象上修补深埋的方法?
- vim - 您如何使用 vimrc 在文件加载时标记特定文本?
- node.js - Drive API - 从字符串更新/创建 Google Doc - Node.js