题目:
在美国,不同的税率是根据纳税人的婚姻状况而定的。单身和已婚的纳税人有不同的税收计划。已婚的纳税人将他们的收入加在一起,并支付总的税。如下表计算税率。不同税率适合于每一个“分支”。在表中,第一个分支的收入为10%,第二个分支的收入为25%。每个分支的收入范围取决于婚姻状况。
代码:
import java.util.Scanner;
public class taxRate
{
private static Scanner in;
public static void main(String[] args)
{
final double rate1 = 0.10;
final double rate2 = 0.25;
final double singleLimit = 32000;
final double marriedLimit = 64000;
double tax1 = 0;
double tax2 = 0;
in = new Scanner(System.in);
System.out.print("please input your income:");
double income = in.nextDouble();
System.out.print("please input s for single or m for married:");
String maritalStatue = in.next();
if(maritalStatue.equals("s"))
{
if(income<=singleLimit)
{
tax1 = rate1 * income;
}
else
{
tax1 = rate1 * singleLimit;
tax2 = rate2 * (income - singleLimit);
}
}
else
{
if(income<=marriedLimit)
{
tax1 = rate1 * income;
}
else
{
tax1 = rate1 * marriedLimit;
tax2 = rate2 * (income - marriedLimit);
}
}
double totalTax = tax1 + tax2;
System.out.println("The tax is $"+totalTax);
}
}
运行结果: