Question:
- create a class named Account that contains the string fields name, email and password.
- Develop a program called LoginSim that simulates a login procedure.
- The program reads a list of names, email addresses and passwords from a file pw.txt.
Store the information in an ArrayList of Account objects. *Note: for Netbeans users the file must be placed in a test folder and accessed with
new File("test/pw.txt");
Your program will prompt the user for their email address.
- If the email is not in the system, prompt the user to try again. Give them an option to quit.
- If the email is found in the system, prompt the user to enter their password.
- After 3 unsuccessful tries, inform the user that they are locked out and end the program.
- If the password matches, welcome the user by name and ask if they would like to change their password.
- If so, prompt for the new password and change it accordingly. If not, end the program by confirming that they have signed out. When the program ends, display the list of accounts.
Sample output:
Enter your email address (q to quit):
draco@hogwarts.com
Email not found, please try again (q to quit):
dmalfoy@hogwarts.com
Email not found, please try again (q to quit):
q
Goodbye!
pw.txt
Hagrid hagrid@hogwarts.com 111
Harry harry@hogwarts.com killvoldy777
Ron ron@hogwarts.com mypassword123
Hermione hermione@hogwarts.com 98fJG83h*4iwrej!
What should I do next, exception at line 16
import java.util.*;
import java.io.*;
public class LoginSim {
private static int index;
public static void main(String args[]) throws
FileNotFoundException, ArrayIndexOutOfBoundsException {
String em;
String pw;
Scanner f = new Scanner(new File("src/pw.txt"));
Scanner kb = new Scanner(System.in);
String[] email = new String[3];
String[] password = new String[3];
int i = 0;
while (f.hasNext()) {
email[i] = String.valueOf(f.hasNext());
password[i] = String.valueOf(f.hasNext());
i++;
}
System.out.println("Enter Email:");
em = kb.next();
System.out.println("Enter Password:");
pw = kb.next();
if (index != -1) {
System.out.println("Enter pw:");
pw = kb.next();
int tries = 0;
while (!pw.equals(tries < 2) &&
!pw.equals(password[index])) {
System.out.println("Incorrect Password, Try Again");
tries++;
pw = kb.next();
}
if (pw.equals(password[index])) {
System.out.println("Successful Login");
}else {
System.out.println("3 Strikes, Locked out");
}
System.out.println("Email not found");
}
}
}