java - -accountId cannot be resolved or is not a field -


i can't figure out what's problem method, have arraylist named accounts i'm trying implement other class' method. i'm getting errormessage: "multiple markers @ line -accountid cannot resolved or not field -accountid cannot resolved or not field"

why doesn't work?

public boolean deposit(long pnr, int accountid, double amount){          for(int = 0; < customerlist.size(); i++)         {             if(this.pnr == pnr)             {                 for(int j = 0; j < accounts.size(); j++)                 {                     if(accountid == accounts.accountid)//problem seem here                     {                         balance = balance + amount;                     }                 }             }             else                 return false;         }         return true;     } 

accounts seems list, should try access field of item of list instead of accessing item of list itself.

if(accountid == accounts.get(j).accountid) {     balance = balance + amount; } 

and should iterate on list iterator or foreach - don't have access every item manually.

i've made changes, have adapt following piece fit in code:

public boolean deposit(long pnr, int accountid, double amount){     for(customer customer : customerlist)     {         if(pnr == customer.getpnr())         {             for(savingsaccount account : accounts)             {                 if(accountid == account.getaccountid())                 {                     balance += amount;                     return true;                 }             }             return false;         }     }     return false; } 

if want access private fields of other objects, have use getter (like getaccountid() or getpnr()) - these methods return "their" private field.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -