嗨,我需要帮助来进行计算。在它有单个的行上,我想将数字添加到计算中,但它只是添加它,就好像我只是将数字本身写在一个句子中一样。我如何添加它,就好像它是一个计算一样,我非常卡住并且需要帮助。(它的最后一行代码)。我还想知道如何限制用户可以输入的字母数量,因为我只希望他们输入“s”或“m”。我怎样才能将它们限制为仅这两个,以便他们不使用例如“g”之类的字母,因为那不起作用。
import java.util.Scanner;
public class FedTaxRate
{
public static void main(String[] args)
{
String maritalStatus;
double income;
int single = 32000;
int married = 64000;
Scanner status = new Scanner(System.in);
System.out.println ("Please enter your marital status: ");
maritalStatus = status.next();
Scanner amount = new Scanner(System.in);
System.out.print ("Please enter your income: ");
income = amount.nextDouble();
if (maritalStatus.equals("s") && income <= 32000 )
{
System.out.println ("The tax is " + income * 0.10 + ".");
}
else if (maritalStatus.equals("s") && income > 32000)
{
System.out.println ("The tax is " + (income - 32000) * 0.25 + single + ".");
}
}
}