3 回答

TA貢獻(xiàn)1786條經(jīng)驗(yàn) 獲得超13個贊
您的代碼有很多問題。
要修復(fù)該 1 方法如下:
從該方法返回一個新的儲蓄賬戶newAccount,因此將返回類型更改為:
public static SavingsAccountUgang newAccount() {
// Your existing code
return savingsAccount;
}
然后在您的displayMainMenu()方法中保存此帳戶,如果用戶輸入 1 作為輸入,然后使用該實(shí)例顯示余額:
public static void displayMainMenu() {
SavingsAccountUgang savingsAccount = null // don't create object here as you are doing
// Your code
if (option == 1) {
savingsAccount = newAccount();
}
if (option == 2) {
if(savingsAccount == null) {
// throw exception or whatever you want to do.
}
savingsAccount.balanceInquiry();
}
}

TA貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超13個贊
好吧,該setBalance()
方法需要一個參數(shù) type double
,但是您發(fā)送了一個 type int
,但這不是錯誤的原因。this
此外,您應(yīng)該在這樣的聲明中使用:
while (accountNumber != this.getAccountNo());

TA貢獻(xiàn)1868條經(jīng)驗(yàn) 獲得超4個贊
SavingsAccountUgang
您方法中的實(shí)例是newAccount()
局部變量,因此僅對此方法可見。如果你想在你的方法之外使用它,你必須在你的方法之外返回或聲明它。
添加回答
舉報