Advertisement
Guest User

AccountLogin Lab - 1-9-17 | 5:33 pm

a guest
Jan 9th, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.41 KB | None | 0 0
  1. package jan6;  
  2. import java.util.Scanner;
  3. public class AccountLogin
  4. {
  5.     static Account[] AccountData = new Account[33]; // Create array of usernames and passwords
  6.    
  7.     public static void main(String []args)
  8.     {
  9.         Scanner in = new Scanner(System.in);
  10.         int exit = 0; // To exit loop
  11.         while (exit == 0)
  12.         {
  13.             System.out.println("Enter 'create' to create an account, 'login' to login to your account or 'exit' to close. ");
  14.             String command = in.nextLine(); // Command input
  15.             command = command.toLowerCase();
  16.            
  17.             int accountNum = 0; // Initialize counter
  18.             if (command.equals("create")) // CREATE ACCOUNT
  19.             {
  20.                 System.out.println("Enter a username: ");
  21.                 String inputUser = in.nextLine();
  22.                 System.out.println("Enter a numeric password: ");
  23.                 int inputPass = in.nextInt();  
  24.                 AccountData[accountNum] = new Account(inputUser, inputPass);
  25.                 accountNum++;
  26.                 System.out.println("This is your username: " + AccountData[0].username);
  27.                 System.out.println("This is your password: " + AccountData[0].password);
  28.             }
  29.             else if (command.equals("login")) // LOGIN TO ACCOUNT
  30.             {
  31.                 boolean validUser = false;
  32.                 System.out.println("Enter your username: ");
  33.                 String loginUser = in.nextLine();
  34.                 int accountNumCheck = 0;
  35.                 int exitLogin = 0;
  36.                 while (exitLogin == 0)
  37.                 {
  38.                     if (loginUser.equals(AccountData[accountNumCheck].username));
  39.                     {
  40.                         System.out.println("Username accepted.");
  41.                         validUser = true;
  42.                         exitLogin++;
  43.                     }
  44.                     if (!loginUser.equals(AccountData[accountNumCheck].username));
  45.                     {
  46.                         accountNumCheck++;
  47.                     }
  48.                     if (accountNumCheck > 33)
  49.                     {
  50.                         System.out.println("Your username isn't valid. Exiting Program.");
  51.                         exitLogin++;
  52.                         exit++;
  53.                     }
  54.                 }
  55.                 if (validUser = true)
  56.                 {
  57.                     System.out.println("Enter your password: ");
  58.                     int loginPass = in.nextInt();
  59.                     if (loginPass == (AccountData[accountNumCheck - 1].password))
  60.                     {
  61.                         System.out.println("Welcome. ");
  62.                         System.out.println("Program Complete");
  63.                         exit++;
  64.                     }
  65.                     else
  66.                     {
  67.                         System.out.println("Password incorrect. Exitting program.");
  68.                         exit++;
  69.                     }
  70.                 }
  71.             }
  72.             else if (command.equals("exit")) // EXIT PROGRAM
  73.             {
  74.                 System.out.println("End Program");
  75.                 exit++;
  76.             }
  77.             // AccountData[0] = new Account("Mr. T", 123);
  78.             // AccountData[0].username
  79.             // AccountData[0].password
  80.         }
  81.         in.close();
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement