您好,我試圖讓我的程序運行,以便您在轉賬時,轉賬費用爲2.0美元僅適用於餘額少於10,000美元的賬戶。如何使用最低餘額費用轉賬
我遇到的問題是無論我的餘額如何,我的代碼都向我收取了轉賬費用。如果我有5,000,000美元的餘額,並且我轉賬$ 9,999美元,那麼我會收取2.0的轉賬費用。
如果我嘗試轉移> 10,000美元,則不需要轉讓費用。請發現我的錯誤。非常感謝。
有5個類,所以我要粘貼下面的所有相關信息。
// CLASS 1
public class AccountConstants {
private final double CHECKING_BALANCE_THRESHOLD = 10000;
private final double TRANSFER_FEE = 2.0;
public double getFee(double amount){
if (amount < CHECKING_BALANCE_THRESHOLD){
return TRANSFER_FEE;
}
return 0.0;
}
public class CheckingAccount extends Account{
public CheckingAccount(String number, String name, GregorianCalendar
openDate, double balance){
super(number,name,openDate,balance);
}
//CLASS 2
@override
public int transferTo(Account account, double amount) {
AccountConstants ac = new AccountConstants();
double fee = ac.getFee(amount);
if (this.getBalance() < amount)
return -2;
else if (this.getBalance() < (amount+fee))
return -1;
else if (this.getBalance()>=(amount+fee)&& fee==2.0){
this.setBalance(-(amount+fee));
account.setBalance(amount);
return 1;
}
else
this.setBalance(-amount);
account.setBalance(amount);
return 0;
}
//CLASS 3
if (result == 0)
{
au.setBalance(jComboBox1.getSelectedIndex(),
accounts.getBalance());
au.setBalance(index, accounts_to.getBalance());
NumberFormat defaultFormat = NumberFormat.getCurrencyInstance();
txtBalance.setText(defaultFormat.format(accounts.getBalance()));
au.updateFile(au.getAccountNumber(index), au.getOpenDate(index),
au.getCustomerName(index), au.getBalance(index));
index = jComboBox1.getSelectedIndex();
au.updateFile(au.getAccountNumber(index), au.getOpenDate(index), au.getCustomerName(index), au.getBalance(index));
JOptionPane.showMessageDialog(this, defaultFormat.format(amount)+" was transfered to "+accountNumber,"Transfer successful", JOptionPane.INFORMATION_MESSAGE);
}
else if (result == 1)
{
au.setBalance(jComboBox1.getSelectedIndex(), accounts.getBalance());
au.setBalance(index, accounts_to.getBalance());
NumberFormat defaultFormat = NumberFormat.getCurrencyInstance();
txtBalance.setText(defaultFormat.format(accounts.getBalance()));
au.updateFile(au.getAccountNumber(index), au.getOpenDate(index),au.getCustomerName(index), au.getBalance(index));
index = jComboBox1.getSelectedIndex();
au.updateFile(au.getAccountNumber(index), au.getOpenDate(index), au.getCustomerName(index), au.getBalance(index));
JOptionPane.showMessageDialog(this, defaultFormat.format(amount)+" was transfered to "+accountNumber+"\n$2.0 transfer fee was applied", "Transfer successful", JOptionPane.INFORMATION_MESSAGE);
}
對不起,新的和謝謝! – Mikeyubuee
老師讓我們挑選這些價值觀,但是謝謝! – Mikeyubuee