-1
我正在學習一個Java類,並且我一直在研究這個程序,該程序基於通過GUI輸入的信息計算信用卡餘額。在我的輸出財務費用,新餘額和新付款到期日均爲0.我嘗試添加5以查明我在哪裏搞砸了,並且在計算newBalance
時似乎沒有正確引用「餘額」。我認爲財務費用也有同樣的問題,但固定餘額也會幫助我解決這個問題。用一種方法計算的變量不會去另一個
//calculates balance
public float calculateBalance()
{
balance = previousBalance + currentPurchases - payments - creditsReturns + lateFees+ 5;
return balance;
}
//sets finance charge
public void setFinanceCharge(float financeCharge)
{
double periodicRate;
periodicRate = .12/12;
float d = (float)periodicRate;
financeCharge = balance * d;
}
//gets finance charge
public float getFinanceCharge()
{
return financeCharge;
}
//Method to calculate new balance
public float calculateNewBalance()
{
//calculate the new balance
newBalance = balance+financeCharge+5;
return newBalance;
}
//setes new payment due
public void setpaymentDue(double newPayment)
{
newPayment = newBalance * .10;
this.paymentDue = (float)newPayment;
}
//gets new payment due
public float getpaymentDue()
{
return paymentDue;
}
//method to display results
public void displayOutput()
{
if (overCreditLimit == 0)
{
JOptionPane.showMessageDialog(null,
"The Customer number is: " + customerNumber + "\n" +
"The Customer name is: " + customerName + "\n" +
"The Credit Limit is: " + creditLimit + "\n" +
"The Previous Balance is: " + previousBalance + "\n" +
"The Current Purchases is: " + currentPurchases + "\n" +
"The Payments is: " + payments + "\n" +
"The Credits/Returns is: " + creditsReturns + "\n" +
"The Late Fees is: " + lateFees + "\n" +
"The Finance Charge is: " + financeCharge + "\n" +
"The New Balance is: " + newBalance + "\n" +
"The New Payment Due is: " + paymentDue + "\n");
}
else
{
overCreditAmount = newBalance - creditLimit - 25;
JOptionPane.showMessageDialog(null, "You are " + overCreditAmount + " dollars over your credit limit,"
+ " a $25 fee has been charged to your new balance");
JOptionPane.showMessageDialog(null,
"The Customer number is: " + customerNumber + "\n" +
"The Customer name is: " + customerName + "\n" +
"The Credit Limit is: " + creditLimit + "\n" +
"The Previous Balance is: " + previousBalance + "\n" +
"The Current Purchases is: " + currentPurchases + "\n" +
"The Payments is: " + payments + "\n" +
"The Credits/Returns is: " + creditsReturns + "\n" +
"The Late Fees is: " + lateFees + "\n" +
"The Finance Charge is: " + financeCharge + "\n" +
"The Amount over Credit Limit is: " + overCreditAmount + "\n" +
"The New Balance is: " + newBalance + "\n" +
"The New Payment Due is: " + paymentDue + "\n");
}
}
爲了解決這個問題,我建議運行calculateNewBalance中的方法而不是調用變量。例如,爲了達到平衡,請調用calculateBalance(),看看會發生什麼。 – OneSurvivor
如果它不起作用,我會建議在方法中創建一個本地變量以取代平衡,並查看它是否有效。如果沒有,那麼您沒有顯示的代碼可能存在問題。 – OneSurvivor