My code compiles but it returns -1 regardless of what I input, correct or not
public int search(String accountNumber){
int index = 0;
boolean found = false;
for (Account account : accounts )
while(index < accounts.size() && !found)
if (accounts.get(index).equals (accountNumber))
found = true;
else
index++;
if (found == true)
return index;
else
return -1;
}
}
Essentially I'm trying to return the account number from that index position but I'm really struggling to solve this
Edit: Also I'm not sure how to correct this in order to make it work
/** Should remove the Account with the account number specified as a parameter if it the Account exists. The appropriate boolean value should then be returned via a method result dialog box. */
public boolean removeAccount(String accountNumber)
{
int index = 0;
for(Account account : accounts)
{
if((account.getAccountNumber() == accountNumber) && index < accounts.size())
accounts.remove(account);
else
index++;
}
}