【发布时间】:2021-05-13 08:02:30
【问题描述】:
用户从 UI 输入税单。然后将税单存储在数据库中。之后从数据库中取出来计算用户的所得税。
@Getter
@Setter
public class TaxSlabDto {
private String maritalStatus;
private int lowerLimit;
private int upperLimit;
private double percent;
public TaxSlabDto(String maritalStatus, int lowerLimit, int upperLimit, double percent) {
this.maritalStatus = maritalStatus;
this.lowerLimit = lowerLimit;
this.upperLimit = upperLimit;
this.percent = percent;
}
}
以下代码是不完整的代码。我想让它完成。我们必须用列表 taxSlabDtos 的值替换下面代码中的静态值(上限、下限、税收百分比)。
public static void main(String[] args) {
List<TaxSlabDto> taxSlabDtos = new ArrayList();
taxSlabDtos.add(new TaxSlabDto("Un Married", 0, 400000, 1));
taxSlabDtos.add(new TaxSlabDto("Un Married", 400001, 500000, 10));
taxSlabDtos.add(new TaxSlabDto("Un Married", 500001, 700000, 20));
taxSlabDtos.add(new TaxSlabDto("Un Married", 700001, 2000000, 30));
taxSlabDtos.add(new TaxSlabDto("Un Married", 2000000, 1000000000, 36));
double tax = 0, income;
Scanner sc = new Scanner(System.in);
System.out.println("Enter income ");
income = sc.nextDouble();
for (TaxSlabDto taxSlabDto : taxSlabDtos) {
if (income <= 400000) {
tax = 1/100 * income;
} else if (income <= 500000) {
tax = (10/100 * (income - 400000)) + (1/100 * 400000);
} else if (income <= 700000) {
tax = (20/100 * (income - 500000)) + ((500000 - 400000) * 10/100) + (1/100 * 400000);
} else if (income <= 2000000) {
tax = ((income - 700000) * 30/100) + (20/100 * (700000 - 500000)) + ((500000 - 400000) * 10/100) + (1/100 * 400000);
} else {
tax = ((income - 2000000) * 36/100) + ((2000000 - 700000) * 30/100) + (20/100 * (700000 - 500000)) + ((500000 - 400000) * 10/100) + (1/100 * 400000);
}
}
System.out.println("Total Income Tax " + tax);
}
目前税收计算不是动态的。这里有哪位Java Genius,可以帮我根据list taxSlabDtos 的值动态计算所得税。
【问题讨论】:
标签: java