Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package jan6;
- import java.util.Scanner;
- public class AccountLogin
- {
- static Account[] AccountData = new Account[33]; // Create array of usernames and passwords
- public static void main(String []args)
- {
- Scanner in = new Scanner(System.in);
- int exit = 0; // To exit loop
- int accountNumCheck = 0;
- int exitLogin = 0;
- while (exit == 0)
- {
- System.out.println("Enter 'create' to create an account, 'login' to login to your account or 'exit' to close. ");
- String command = in.nextLine(); // Command input
- command = command.toLowerCase();
- int accountNum = 0; // Initialize counter
- if (command.equals("create")) // CREATE ACCOUNT
- {
- System.out.println("Enter a username: ");
- String inputUser = in.nextLine();
- System.out.println("Enter a numeric password: ");
- int inputPass = in.nextInt();
- AccountData[accountNum] = new Account(inputUser, inputPass);
- accountNum++;
- System.out.println("This is your username: " + AccountData[0].username);
- System.out.println("This is your password: " + AccountData[0].password);
- }
- else if (command.equals("login")) // LOGIN TO ACCOUNT
- {
- System.out.println("Enter your username: ");
- String loginUser = in.nextLine();
- System.out.println("Enter your password: ");
- int loginPass = in.nextInt();
- while (exitLogin == 0)
- {
- if (accountNumCheck > 33)
- {
- System.out.println("Account doesn't exist. Exitting program.");
- exit++;
- exitLogin++;
- }
- if (loginUser.equals(AccountData[accountNumCheck].username) && loginPass == AccountData[accountNumCheck].password)
- {
- System.out.println("Welcome. \nProgram will now exit.");
- exit++;
- exitLogin++;
- }
- else
- {
- accountNumCheck++;
- }
- }
- }
- else if (command.equals("exit")) // EXIT PROGRAM
- {
- System.out.println("End Program");
- exit++;
- }
- }
- in.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement