Java_CH8_HW1


  1. import java.util.*;
  2. public class Java_CH8_HW1
  3. {
  4.  
  5. public static void main(String[] args)
  6. {
  7. // TODO 自動產生的方法 Stub
  8. double a = 0, b = 0;
  9. char opr = (char) -1;
  10. Tax_Calculation demo = new Tax_Calculation();
  11. System.out.println("enter single/married s or m");
  12. try
  13. {
  14. opr = (char) System.in.read();
  15. }
  16. catch (Exception e)
  17. {
  18. System.out.println("Error : " + e.toString());
  19. }
  20. System.out.println("enter your income : ");
  21. Scanner sc = new Scanner(System.in);
  22. a = sc.nextFloat();
  23. switch (opr)
  24. {
  25. case 's' :
  26. System.out.println("Your martial status : single. Your tax = "
  27. + demo.single(a));
  28. break;
  29. case 'm' :
  30. System.out.println("Your martial status : married, Your tax ="
  31. + demo.married(a));
  32. break;
  33. default :
  34. System.out.println(" Unknown status ");
  35. }
  36. }
  37.  
  38. }
  39.  
  40. class Tax_Calculation
  41. {
  42. double y, z;
  43. public double single(double y)
  44. {
  45. this.y = y;
  46. if (y > 0 && y <= 21450)
  47. {
  48. z = y * 0.15;
  49. }
  50. if (y > 21450 && y <= 51900)
  51. {
  52. z = (y - 21450) * 0.28 + 3217.5;
  53. }
  54. if (y > 51900)
  55. {
  56. z = (y - 51900) * 0.31 + 11743.5;
  57. }
  58. return z;
  59. }
  60.  
  61. public double married(double y)
  62. {
  63. this.y = y;
  64. if (y > 0 && y <= 35800)
  65. z = y * 0.15;
  66. else if (y < 86500)
  67. z = (y - 35800) * 0.28 + 3217.5;
  68. else if (y > 86500)
  69. z = (y - 86500) * 0.31 + 11743.5;
  70. return z;
  71. }
  72. }

留言

這個網誌中的熱門文章

C# 井字遊戲