Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package loginLab;
- 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)
- {
- boolean exitMain = false;
- int weirdBug = 0; // Counter so the print statement doesn't print twice, strange error
- int accountNum = 0; // Account number counter
- Scanner in = new Scanner(System.in);
- while (exitMain == false)
- {
- if (weirdBug % 2 == 0)
- {
- System.out.println("Would you like to *login* to your account, *create* an account, or *exit*?");
- }
- weirdBug++;
- String command = in.nextLine();
- command = command.toLowerCase();
- if (command.equals("create"))
- {
- boolean exitCreate = false;
- while (exitCreate == false)
- {
- System.out.println("Enter a username: ");
- String inputUser = in.nextLine();
- System.out.println("Enter a numeric password: ");
- int inputPass = in.nextInt();
- if (accountNum < 33)
- {
- AccountData[accountNum] = new Account(inputUser, inputPass);
- accountNum++;
- exitCreate = true;
- }
- else
- {
- System.out.println("No more accounts can be created.");
- exitCreate = true;
- }
- }
- }
- else if (command.equals("login"))
- {
- System.out.println("Enter your username: ");
- String username = in.nextLine();
- System.out.println("Enter your password: ");
- int password = in.nextInt();
- int searchCount = 0;
- boolean exitLogin = false;
- while (exitLogin == false && searchCount <= accountNum - 1)
- {
- if (username.equals(AccountData[searchCount].username) && (password == AccountData[searchCount].password))
- {
- System.out.println("Welcome. \nProgram will now exit.");
- exitLogin = true;
- exitMain = true;
- }
- searchCount++;
- }
- if (searchCount >= accountNum && exitLogin == false)
- {
- System.out.println("Your password and/or username is incorrect. \rReturning you to the main menu.");
- }
- }
- else if (command.equals("exit"))
- {
- System.out.println("Entered \"exit\". Program will now exit.");
- exitMain = true;
- }
- }
- in.close();
- }
- }
Add Comment
Please, Sign In to add comment