Can I have a program for Password of an Account using Super keyword and Exception handling? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

12th Feb 2017, 4:28 PM
sai bhaskar
sai bhaskar - avatar
2 Answers
+ 1
Yes, you can have one. Just code it... Or let us know what you have done already to help you.
12th Feb 2017, 5:33 PM
Tashi N
Tashi N - avatar
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.
13th Feb 2017, 4:28 AM
Varun Moghe
Varun Moghe - avatar