したがって、このプログラムには銀行口座があり、ユーザーが残高を変更できるようにする方法に取り組んでいます。これが私が持っているものです。
public double modifyBalance(int accountID, double adjustment) {
Account temp = findAccount(accountID, 0, size, lastPos);
double currBal = temp.getBalance();
if (temp!= null){
currBal = currBal + adjustment;
}
else {
System.out.println("No account found. ");
}
return currBal;
}
しかし、currBalの戻りは実際のアカウントの残高を更新していません。試しtemp.getBalance() = currBal;
ましたが、うまくいきませんでした。コンパイルエラーが発生しました。
OrderedVectorOfAccounts.java:95:エラー:シンボルが見つかりません
temp.getBalance = currBal;
^
シンボル:変数getBalance
場所:タイプアカウント
1エラーの可変温度
例:アカウントの残高が200で、200を「入金」または追加した場合、400になるはずですが、私が持っているものでは200のままです
。ありがとう!
これは私のfindAccount()です:
public Account findAccount(int accountID, int from, int to, int [] lastPos){
if(from > to || (from+2)/2 >= size)
return null;
while(from <=to) {
if(accountID == theAccounts[(from+to)/2].getAccountNum())
return theAccounts[(from + to)/2];
else if (accountID>theAccounts[(from + to)/2].getAccountNum()){
// return findAccount(accountID, (((from + to)/2)+1), to, lastPos);
return theAccounts[accountID-1];
}
else if (accountID<theAccounts[(from + to)/2].getAccountNum()){
//return findAccount(accountID, from, (((from + to)/2)-1),lastPos);
return theAccounts[accountID-1];
}
}
lastPos[0] = (from + to)/2;
return null;