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. double tax = 0;
  13. if (status == 0) {
  14. if ( income <= 8350){
  15. tax = income * 0.10;
  16. } else if (income <= 33950) {
  17. tax = (8350 * 0.10) + (income-8350) * 0.15;
  18. } else if (income <= 82250) {
  19. tax = (8350 * 0.10) + ((33950-8350) * 0.15) + ((income-33950) * 0.25);
  20. } else if (income <= 171550) {
  21. tax = (8350 * 0.10) + ((33950-8350) * 0.15) + ((82250-33950) * 0.25) + ((income-82250) * 0.28);
  22. } else if (income <= 372950) {
  23. tax = (8350 * 0.10) + ((33950-8350) * 0.15) + ((82250-33950) * 0.25) + ((171500-82250) * 0.28) + ((income-171550) * 0.33);
  24. } else if ( income >= 372951) {
  25. tax = (8350 * 0.10) + ((33950-8350) * 0.15) + ((82250-33950) * 0.25) + ((171550-82250) * 0.28) + ((372950-171550) * 0.33) + ((income-372950) * 0.35);
  26. } else {
  27. System.out.println("Taxable income can not be negative!");
  28. }
  29. }
  30. if (status == 1) {
  31. if ( income <= 16700){
  32. tax = income * 0.10;
  33. } else if (income <= 67900) {
  34. tax = (16700 * 0.10) + (income-16700) * 0.15;
  35. } else if (income <= 137050) {
  36. tax = (16700 * 0.10) + ((67900-16700) * 0.15) + ((income-67900) * 0.25);
  37. } else if (income <= 208850) {
  38. tax = (16700 * 0.10) + ((67900-16700) * 0.15) + ((137050-67900) * 0.25) + ((income-137050) * 0.28);
  39. } else if (income <= 372950) {
  40. tax = (16700 * 0.10) + ((67900-16700) * 0.15) + ((137050-67900) * 0.25) + ((208850-137050) * 0.28) + ((income-208850) * 0.33);
  41. } else if ( income >= 372951) {
  42. tax = (16700 * 0.10) + ((67900-16700) * 0.15) + ((137050-67900) * 0.25) + ((208850-137050) * 0.28) + ((372950-208850) * 0.33) + ((income-372950) * 0.35);
  43. } else {
  44. System.out.println("Taxable income can not be negative!");
  45. }
  46. }
  47. if (status == 2) {
  48. if ( income <= 8350){
  49. tax = income * 0.10;
  50. } else if (income <= 33950) {
  51. tax = (8350 * 0.10) + (income-8350) * 0.15;
  52. } else if (income <= 68525) {
  53. tax = (8350 * 0.10) + ((33950-8350) * 0.15) + ((income-33950) * 0.25);
  54. } else if (income <= 104425) {
  55. tax = (8350 * 0.10) + ((33950-8350) * 0.15) + ((68525-33950) * 0.25) + ((income-68525) * 0.28);
  56. } else if (income <= 186475) {
  57. tax = (8350 * 0.10) + ((33950-8350) * 0.15) + ((68525-33950) * 0.25) + ((104425-68525) * 0.28) + ((income-104425) * 0.33);
  58. } else if ( income >= 186476) {
  59. tax = (8350 * 0.10) + ((33950-8350) * 0.15) + ((68525-33950) * 0.25) + ((104425-68525) * 0.28) + ((186475-104425) * 0.33) + ((income-186475) * 0.35);
  60. } else {
  61. System.out.println("Taxable income can not be negative!");
  62. }
  63. }
  64. if (status == 3) {
  65. if ( income <= 11950){
  66. tax = income * 0.10;
  67. } else if (income <= 45500) {
  68. tax = (11950 * 0.10) + (income-11950) * 0.15;
  69. } else if (income <= 117450) {
  70. tax = (11950 * 0.10) + ((45500-11950) * 0.15) + ((income-45500) * 0.25);
  71. } else if (income <= 190200) {
  72. tax = (11950 * 0.10) + ((45500-11950) * 0.15) + ((117450-45500) * 0.25) + ((income-117450) * 0.28);
  73. } else if (income <= 372950) {
  74. tax = (11950 * 0.10) + ((45500-11950) * 0.15) + ((117450-45500) * 0.25) + ((190200-117450) * 0.28) + ((income-190200) * 0.33);
  75. } else if ( income >= 372951) {
  76. tax = (11950 * 0.10) + ((45500-11950) * 0.15) + ((117450-45500) * 0.25) + ((190200-117450) * 0.28) + ((372950-190200) * 0.33) + ((income-372950) * 0.35);
  77. } else {
  78. System.out.println("Taxable income can not be negative!");
  79. }
  80. }
  81. System.out.println("Tax is " + tax);
  82. }
  83. }
  84.  
Runtime error #stdin #stdout #stderr 0.09s 2184192KB
stdin
1 
321
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: 
stderr
Exception in thread "main" java.lang.NumberFormatException: For input string: "1 "
	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
	at java.lang.Integer.parseInt(Integer.java:580)
	at java.lang.Integer.parseInt(Integer.java:615)
	at Main.main(Main.java:9)