收到“Just Tax”问题。程序编译时,不会计算销售税 - 仅返回“0”。然而,“销售”方法(不在列出的代码中)将确认并打印出售金额。不知道我做错了什么。谢谢!Java:返回用户输入
//...
Purchase saleAmount = new Purchase();
//...
System.out.println("Please enter a positive (+) number for the sale amount: $");
double saleAmt = input.nextDouble();
saleAmount.setSale(saleAmt);
//...
System.out.println("The 5% tax applied is: " + saleAmount.getJustTax());
public class Purchase
//all data types have been declared
final double SALES_TAX = 0.05;
{
//Initial Sale Cost
public double getSale()
{
return sale;
}
public void setSale(double amount)
{
amount = sale;
}
//Get Just Sales Tax
public double getJustTax()
{
return justTax;
}
public void setJustTax(double sale)
{
justTax = (sale * SALES_TAX);
}
}
你调用了'setJustTax()'来计算'justTax'吗? – nikis