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 += (income > 8350 ? 8350 : income) * 0.10;
  19. if (income > 8350) {
  20. tax += ((income > 33950 ? 33950 : income) - 8350) * 0.15;
  21. }
  22. if (income > 33950) {
  23. tax += ((income > 82250 ? 82250 : income) - 33950) * 0.25;
  24. }
  25. if (income > 82250) {
  26. tax += ((income > 171500 ? 171500 : income) - 82250) * 0.28;
  27. }
  28. if (income > 171500) {
  29. tax += ((income > 372950 ? 372950 : income) - 171550) * 0.33;
  30. }
  31. if ( income > 372950) {
  32. tax += (income - 372950) * 0.35;
  33. }
  34. }
  35. if (status == 1) {
  36. if ( income <= 16700){
  37. tax = income * 0.10;
  38. } else if (income <= 67900) {
  39. tax = (16700 * 0.10) + (income-16700) * 0.15;
  40. } else if (income <= 137050) {
  41. tax = (16700 * 0.10) + ((67900-16700) * 0.15) + ((income-67900) * 0.25);
  42. } else if (income <= 208850) {
  43. tax = (16700 * 0.10) + ((67900-16700) * 0.15) + ((137050-67900) * 0.25) + ((income-137050) * 0.28);
  44. } else if (income <= 372950) {
  45. tax = (16700 * 0.10) + ((67900-16700) * 0.15) + ((137050-67900) * 0.25) + ((208850-137050) * 0.28) + ((income-208850) * 0.33);
  46. } else if ( income >= 372951) {
  47. tax = (16700 * 0.10) + ((67900-16700) * 0.15) + ((137050-67900) * 0.25) + ((208850-137050) * 0.28) + ((372950-208850) * 0.33) + ((income-372950) * 0.35);
  48. }
  49. }
  50. if (status == 2) {
  51. if ( income <= 8350){
  52. tax = income * 0.10;
  53. } else if (income <= 33950) {
  54. tax = (8350 * 0.10) + (income-8350) * 0.15;
  55. } else if (income <= 68525) {
  56. tax = (8350 * 0.10) + ((33950-8350) * 0.15) + ((income-33950) * 0.25);
  57. } else if (income <= 104425) {
  58. tax = (8350 * 0.10) + ((33950-8350) * 0.15) + ((68525-33950) * 0.25) + ((income-68525) * 0.28);
  59. } else if (income <= 186475) {
  60. tax = (8350 * 0.10) + ((33950-8350) * 0.15) + ((68525-33950) * 0.25) + ((104425-68525) * 0.28) + ((income-104425) * 0.33);
  61. } else if ( income >= 186476) {
  62. tax = (8350 * 0.10) + ((33950-8350) * 0.15) + ((68525-33950) * 0.25) + ((104425-68525) * 0.28) + ((186475-104425) * 0.33) + ((income-186475) * 0.35);
  63. }
  64. }
  65. if (status == 3) {
  66. if ( income <= 11950){
  67. tax = income * 0.10;
  68. } else if (income <= 45500) {
  69. tax = (11950 * 0.10) + (income-11950) * 0.15;
  70. } else if (income <= 117450) {
  71. tax = (11950 * 0.10) + ((45500-11950) * 0.15) + ((income-45500) * 0.25);
  72. } else if (income <= 190200) {
  73. tax = (11950 * 0.10) + ((45500-11950) * 0.15) + ((117450-45500) * 0.25) + ((income-117450) * 0.28);
  74. } else if (income <= 372950) {
  75. tax = (11950 * 0.10) + ((45500-11950) * 0.15) + ((117450-45500) * 0.25) + ((190200-117450) * 0.28) + ((income-190200) * 0.33);
  76. } else if ( income >= 372951) {
  77. tax = (11950 * 0.10) + ((45500-11950) * 0.15) + ((117450-45500) * 0.25) + ((190200-117450) * 0.28) + ((372950-190200) * 0.33) + ((income-372950) * 0.35);
  78. }
  79. }
  80. System.out.println("Tax is " + tax);
  81. }
  82. }
  83.  
Success #stdin #stdout 0.07s 2184192KB
stdin
1
31311
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 3861.65