113k views
2 votes
Chapter 9.4 project The ATM program allows a user an indefinite number of attempts to log in. Fix the program message that the police will be called after a user has three successive failures. The program should also disable the login button when this happens

1 Answer

3 votes

Final answer:

To fix the program to call the police after three successive login failures, you can add a counter that keeps track of the number of failures. Once the counter reaches three, you can display a message stating that the police will be called and disable the login button.

Step-by-step explanation:

To fix the program to call the police after three successive login failures, you can add a counter that keeps track of the number of failures. Whenever the user fails to log in, the counter should be incremented. Once the counter reaches three, you can display a message stating that the police will be called and disable the login button.

Here's an example of how you can implement this in your code:

int loginAttempts = 0;

public void loginButtonClick() {
if (checkLogin()) {
// Successful login
} else {
loginAttempts++;
if (loginAttempts == 3) {
showMessage("The police will be called!");
disableLoginButton();
}
}
}

In this example, the loginAttempts variable keeps track of the number of failed login attempts. If it reaches three, the showMessage function is called to display a message, and the disableLoginButton function is called to disable the login button.

User Kilise
by
8.4k points

No related questions found