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
- 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
- {
- boolean validUser = false;
- System.out.println("Enter your username: ");
- String loginUser = in.nextLine();
- int accountNumCheck = 0;
- int exitLogin = 0;
- while (exitLogin == 0)
- {
- if (loginUser.equals(AccountData[accountNumCheck].username));
- {
- System.out.println("Username accepted.");
- validUser = true;
- exitLogin++;
- }
- if (!loginUser.equals(AccountData[accountNumCheck].username));
- {
- accountNumCheck++;
- }
- if (accountNumCheck > 33)
- {
- System.out.println("Your username isn't valid. Exiting Program.");
- exitLogin++;
- exit++;
- }
- }
- if (validUser = true)
- {
- System.out.println("Enter your password: ");
- int loginPass = in.nextInt();
- if (loginPass == (AccountData[accountNumCheck - 1].password))
- {
- System.out.println("Welcome. ");
- System.out.println("Program Complete");
- exit++;
- }
- else
- {
- System.out.println("Password incorrect. Exitting program.");
- exit++;
- }
- }
- }
- else if (command.equals("exit")) // EXIT PROGRAM
- {
- System.out.println("End Program");
- exit++;
- }
- // AccountData[0] = new Account("Mr. T", 123);
- // AccountData[0].username
- // AccountData[0].password
- }
- in.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement