Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package loginLab;
- import java.util.Scanner;
- public class Login
- {
- static Account[] AccountData = new Account[33]; // Create array of usernames and passwords
- public static void main(String []args)
- {
- for (int i = 0; i < 33; i++)
- {
- AccountData[i] = new Account("temp", 000);
- }
- boolean exitMain = false;
- int weirdBug = 0; // Counter so the print statement doesn't print twice, strange error
- Scanner in = new Scanner(System.in);
- while (exitMain == false)
- {
- boolean exitLogin = 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();
- if (command.equals("create"))
- {
- int accountNum = 0; // Account number counter
- 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++;
- System.out.println("This is your username: " + AccountData[accountNum].username);
- System.out.println("This is your password: " + AccountData[accountNum].password);
- }
- else
- {
- System.out.println("No more accounts can be created.");
- }
- }
- else if (command.equals("login"))
- {
- int accountNum = 0; // Account number counter
- System.out.println("Enter your username: ");
- String username = in.nextLine();
- while (exitLogin == false)
- {
- if (accountNum >= 33) // Username DNE
- {
- System.out.println("Username doesn't exist. Returning to main menu.");
- exitLogin = true;
- }
- else // Username exists
- {
- if (username.equals(AccountData[accountNum].username)) // Username found
- {
- }
- else
- {
- accountNum++;
- }
- }
- }
- }
- else if (command.equals("exit"))
- {
- System.out.println("Entered \"exit\". Program will now exit.");
- exitMain = true;
- }
- }
- in.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement