I have a linked list full of employees for testing, I would like to iterate through it and see if an employee is found then return true, this does work slightly however it will only find the last employee in the list, what am I doing wrong? Also I have different types of employee such as manager who inherit from the account class, sorry if thats confusing! Sorry still a beginner!! Thanks
Here is my list with the accounts added:
LinkedList<Account> Accounts = new LinkedList<Account>();
Employee John = new Account("John", "password1");
Manager Bob = new Account("Bob", "password2");
Here is the method which finds the employee/account.
private boolean check(String employee) {
for (Account e : Accounts) {
if (e.getEmployee().equals(employee)) {
return true;
}
}
return false;
}
EDIT: Below is the code i have added, it works however only for the last user. I would like the method to return true if the account name is found in the linked list, so that the system can continue and ask for further info etc.., the name variable is located in my Account class
private boolean check(String employee){
for(Account a : accounts){
if(a.name.equals(employee)){
return true;
}
}
return false;
}