fork download
  1. import java.util.Scanner;
  2. public class Main {
  3. public static void main(String[] args) {
  4. Scanner reader = new Scanner(System.in);
  5. System.out.println("Which filing status number suits you? ");
  6. System.out.println("0. Single filer\n1. Married filing jointly\n2. Married filing seperately\n3. Head of household");
  7. System.out.println("");
  8. System.out.print("Enter the filing status: ");
  9. int status = Integer.parseInt(reader.nextLine());
  10. System.out.print("Enter the taxable income: ");
  11. double income = Double.parseDouble(reader.nextLine());
  12. if (income < 0){
  13. System.out.println("Taxable income can not be negative!");
  14. return ;
  15. }
  16. double tax = 0;
  17. if (status == 0) {
  18. tax += addTaxForBracketIfIncomeHighEnough(income, 0, 8350, 0.10);
  19. tax += addTaxForBracketIfIncomeHighEnough(income, 8350, 33950, 0.15);
  20. tax += addTaxForBracketIfIncomeHighEnough(income, 33950, 82250, 0.25);
  21. tax += addTaxForBracketIfIncomeHighEnough(income, 82250, 171500, 0.28);
  22. tax += addTaxForBracketIfIncomeHighEnough(income, 171550, 372950, 0.33);
  23. tax += addTaxForBracketIfIncomeHighEnough(income, 372950, Double.MAX_VALUE, 0.35);
  24. }
  25. if (status == 1) {
  26. if ( income <= 16700){
  27. tax = income * 0.10;
  28. } else if (income <= 67900) {
  29. tax = (16700 * 0.10) + (income-16700) * 0.15;
  30. } else if (income <= 137050) {
  31. tax = (16700 * 0.10) + ((67900-16700) * 0.15) + ((income-67900) * 0.25);
  32. } else if (income <= 208850) {
  33. tax = (16700 * 0.10) + ((67900-16700) * 0.15) + ((137050-67900) * 0.25) + ((income-137050) * 0.28);
  34. } else if (income <= 372950) {
  35. tax = (16700 * 0.10) + ((67900-16700) * 0.15) + ((137050-67900) * 0.25) + ((208850-137050) * 0.28) + ((income-208850) * 0.33);
  36. } else if ( income >= 372951) {
  37. tax = (16700 * 0.10) + ((67900-16700) * 0.15) + ((137050-67900) * 0.25) + ((208850-137050) * 0.28) + ((372950-208850) * 0.33) + ((income-372950) * 0.35);
  38. }
  39. }
  40. if (status == 2) {
  41. if ( income <= 8350){
  42. tax = income * 0.10;
  43. } else if (income <= 33950) {
  44. tax = (8350 * 0.10) + (income-8350) * 0.15;
  45. } else if (income <= 68525) {
  46. tax = (8350 * 0.10) + ((33950-8350) * 0.15) + ((income-33950) * 0.25);
  47. } else if (income <= 104425) {
  48. tax = (8350 * 0.10) + ((33950-8350) * 0.15) + ((68525-33950) * 0.25) + ((income-68525) * 0.28);
  49. } else if (income <= 186475) {
  50. tax = (8350 * 0.10) + ((33950-8350) * 0.15) + ((68525-33950) * 0.25) + ((104425-68525) * 0.28) + ((income-104425) * 0.33);
  51. } else if ( income >= 186476) {
  52. tax = (8350 * 0.10) + ((33950-8350) * 0.15) + ((68525-33950) * 0.25) + ((104425-68525) * 0.28) + ((186475-104425) * 0.33) + ((income-186475) * 0.35);
  53. }
  54. }
  55. if (status == 3) {
  56. if ( income <= 11950){
  57. tax = income * 0.10;
  58. } else if (income <= 45500) {
  59. tax = (11950 * 0.10) + (income-11950) * 0.15;
  60. } else if (income <= 117450) {
  61. tax = (11950 * 0.10) + ((45500-11950) * 0.15) + ((income-45500) * 0.25);
  62. } else if (income <= 190200) {
  63. tax = (11950 * 0.10) + ((45500-11950) * 0.15) + ((117450-45500) * 0.25) + ((income-117450) * 0.28);
  64. } else if (income <= 372950) {
  65. tax = (11950 * 0.10) + ((45500-11950) * 0.15) + ((117450-45500) * 0.25) + ((190200-117450) * 0.28) + ((income-190200) * 0.33);
  66. } else if ( income >= 372951) {
  67. tax = (11950 * 0.10) + ((45500-11950) * 0.15) + ((117450-45500) * 0.25) + ((190200-117450) * 0.28) + ((372950-190200) * 0.33) + ((income-372950) * 0.35);
  68. }
  69. }
  70. System.out.println("Tax is " + tax);
  71. }
  72.  
  73. private static double addTaxForBracketIfIncomeHighEnough(double income, double lowerLimit, double upperLimit, double percentageOfBracket) {
  74. if (income <= lowerLimit){
  75. return 0;
  76. }
  77. return ((income > upperLimit ? upperLimit : income) - lowerLimit) * percentageOfBracket;
  78. }
  79. }
  80.  
Success #stdin #stdout 0.08s 2184192KB
stdin
1
13
stdout
Which filing status number suits you? 
0. Single filer
1. Married filing jointly
2. Married filing seperately
3. Head of household

Enter the filing status: Enter the taxable income: Tax is 1.3