所以在这个程序中有银行账户,我正在研究一种允许用户更改余额的方法,这就是我所拥有的:
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
位置:Account
1 类型的变量 temp 错误
例如:如果帐户的余额是 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;