1. class Caculate{
  2. private String name;
  3. private double money;
  4. private double actual;
  5. /**
  6. * @param username 用户名
  7. * @param money 用户税前收入
  8. */
  9. public Caculate(String username,double money) {
  10. this.name=username;
  11. this.money=money;
  12. }
  13. public  double HowMany(){
  14. //java中switch的case变量只支持int char string,而此处是double,所以不能使用switch
  15. double shouru = money;//构造函数中本来已经有this.money了,所以再次使用的使用,用成money即可
  16. if(shouru <= 1500){
  17. System.out.print("不需要缴纳个人所得税");
  18. this.actual=shouru;
  19. }else if(1500 < shouru && shouru < 3000){
  20. this.actual = shouru*(1 - 0.05);
  21. }if(3000 <= shouru){
  22. this.actual=shouru-(shouru-3000)*0.1;
  23. }
  24. System.out.println("实际收入为:"+this.actual);
  25. return this.actual;
  26. }
  27. }
  28. /**
  29. * @author 码农小江
  30. * PersonalFax.java
  31. * 2012-8-7下午11:28:16
  32. */
  33. public class PersonalFax {
  34. public static void main(String args[]){
  35. Caculate  shiji = new Caculate("码农小江", 1000.2345);
  36. double shou =shiji.HowMany();
  37. System.out.printf("%.3f", shou);
  38. }
  39. }
05-11 11:05
查看更多