我正在做一個Java項目,我被困在了一部分。我有存款功能在SavingsAccount類中工作,但我似乎無法弄清楚如何在引擎類中調用它。對於我們的項目,我們必須允許用戶使用BlueJ虛擬機創建多個銀行賬戶並在它們之間轉移資金。我會發布我的引擎類和儲蓄帳戶類的相關代碼...謝謝,任何幫助將不勝感激!銀行帳戶轉移項目Java
問題:我無法從一個帳戶轉移到另一個帳戶,我在引擎類上收到錯誤消息。我覺得我做的事情錯了,我寄錢給帳戶...
儲蓄賬戶代碼
public class SavingsAccount extends BankAccount
public void transfer (BankAccount that, double amount)
{
if
(balance-amount < -80)
balance = balance ;
else
{
if
(amount <= balance)
{
this.balance = this.balance - amount;
that.balance = that.balance + amount;
}
else
{
this.balance = this.balance - amount-20;
that.balance = that.balance + amount;
}
}
}
引擎類
public class engine
{
SavingsAccount savings1 = new SavingsAccount();
savings1.balance = 0;
//code for other choices, such as deposit and withdraw...
if (selection2 == 3)
{
System.out.println ("How much would you like to transfer?");
int transferAmount = in.nextInt ();
System.out.println ("Which account would you like to transfer the money to?");
String thatAccount = in.next();
savings1.withdraw (transferAmount);
thatAccount.deposit (transferAmount);
System.out.println ("You account balance is " + savings1.getBalance() + "!");
}
我不明白你的問題。 –
無論你在做什麼,你都不應該在涉及金錢的地方雙倍使用。改用BigDecimal。 –
我無法從一個帳戶轉移到另一個帳戶,我在引擎類上出現錯誤。我想我正在爲我匯款的帳戶做錯了什麼... – user1691618