Advertisement
Guest User

AccountLogin Lab - 1-11-17 | 7:32 pm

a guest
Jan 11th, 2017
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. package loginLab;
  2. import java.util.Scanner;
  3. public class Login
  4. {
  5. static Account[] AccountData = new Account[33]; // Create array of usernames and passwords
  6.  
  7. public static void main(String []args)
  8. {
  9. for (int i = 0; i < 33; i++)
  10. {
  11. AccountData[i] = new Account("temp", 000);
  12. }
  13. boolean exitMain = false;
  14. int weirdBug = 0; // Counter so the print statement doesn't print twice, strange error
  15. Scanner in = new Scanner(System.in);
  16. while (exitMain == false)
  17. {
  18. boolean exitLogin = false;
  19. if (weirdBug % 2 == 0)
  20. {
  21. System.out.println("Would you like to *login* to your account, *create* an account, or *exit*?");
  22. }
  23. weirdBug++;
  24. String command = in.nextLine();
  25. if (command.equals("create"))
  26. {
  27. int accountNum = 0; // Account number counter
  28. System.out.println("Enter a username: ");
  29. String inputUser = in.nextLine();
  30. System.out.println("Enter a numeric password: ");
  31. int inputPass = in.nextInt();
  32. if (accountNum < 33)
  33. {
  34. AccountData[accountNum] = new Account(inputUser, inputPass);
  35. accountNum++;
  36. System.out.println("This is your username: " + AccountData[accountNum].username);
  37. System.out.println("This is your password: " + AccountData[accountNum].password);
  38. }
  39. else
  40. {
  41. System.out.println("No more accounts can be created.");
  42. }
  43. }
  44.  
  45. else if (command.equals("login"))
  46. {
  47. int accountNum = 0; // Account number counter
  48. System.out.println("Enter your username: ");
  49. String username = in.nextLine();
  50. while (exitLogin == false)
  51. {
  52. if (accountNum >= 33) // Username DNE
  53. {
  54. System.out.println("Username doesn't exist. Returning to main menu.");
  55. exitLogin = true;
  56. }
  57. else // Username exists
  58. {
  59. if (username.equals(AccountData[accountNum].username)) // Username found
  60. {
  61.  
  62. }
  63. else
  64. {
  65. accountNum++;
  66. }
  67. }
  68. }
  69.  
  70. }
  71.  
  72. else if (command.equals("exit"))
  73. {
  74. System.out.println("Entered \"exit\". Program will now exit.");
  75. exitMain = true;
  76. }
  77. }
  78. in.close();
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement