收到「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