/** A supposed existent user tries to login to our system. */ private void logIn() { boolean check; boolean exists = false; int tries = 0; String user, pass; Person pers = null; /** Trying to select the person by its username. Maximum number of tries: 3. */ while (!exists && tries < 3) { int i; Consola.escriu("Insert username: "******"Invalid username, please try again."); tries += 1; } } /** * If we reached the end, we wither have a person or we have more than 3 tries. More than 3 * tries means that exists = false. Let's ask for the password in the case that exists is true. */ if (exists) { exists = false; tries = 0; // You can try 3 times for your password. while (!exists && tries < 3) { Consola.escriu("Insert password: "******"Correct password"); } else { Consola.escriu("Incorrect password."); tries += 1; } } } /** * We can have two situations: either we have a correct person (with correct user and password) * or we have exceeded the maximum tries permited. If we have a correct person, we show the * pertinent menu. If we reach here with more than 3 tries, then you can't log in. */ if (pers instanceof Client && tries < 3) { // Given the client, we have to check if he can logIn // id est, if he has less than 3 admonishes. if (((Client) pers).canLogIn()) { // Succeed, the client can log in and is now in use of our application. current = pers; selectOptionMenuClient(); } else { // Our client can log in =( Inform him/her. Consola.escriu("You have 3 admonishes, you can't log in, sorry."); } } else if (pers instanceof Manager && tries < 3) { current = pers; selectOptionMenuManager(); } else if (pers instanceof Admin && tries < 3) { current = pers; selectOptionMenuAdmin(); } else { Consola.escriu("You've exceeded the maximum permited tries"); } }