0
Can I have a program for Password of an Account using Super keyword and Exception handling?
Use two different classes and a super keyword. After 3 attempts of password failure block it for a day
2 Antworten
+ 1
Yes, you can have one. Just code it...
Or let us know what you have done already to help you.
0
import java.util.Scanner;
class PasswordChecker {
static String password = "password";
PasswordChecker(String userInput) {
if (password.equals(userInput)) {
System.out.println("Welcome!");
}
else {
System.out.println("Wrong password!");
Account.takeUserInput();
}
}
}
public class Account extends PasswordChecker {
static String userInput = "";
static int count = 0;
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
takeUserInput();
}
public static void takeUserInput() {
count++;
if (count > 3) {
System.out.println("You have exceeded the limit, your account has been blocked for 1 day.");
System.exit(0);
}
else {
System.out.println("Enter the account password.");
userInput = sc.next();
Account a = new Account();
}
}
Account() {
super(userInput);
}
}
Try this code in your computer, it works perfectly but it gives an error in the app, still haven't figured out why? But it works on pc.