Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.30 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Login2
  3. {
  4. static Account[] AccountData = new Account[33];
  5. public static void main(String[] args)
  6. {
  7. int INVALID = 0;
  8. boolean exitMain = false;
  9. Scanner in = new Scanner(System.in);
  10. AccountData[0] = new Account("kyle", 123, true);
  11. while (exitMain == false)
  12. {
  13. int accountNum = 1;
  14. if (INVALID % 2 == 0)
  15. {
  16. System.out.println("Create, Login, or Exit?");
  17. }
  18. INVALID++;
  19. String command = in.nextLine();
  20. command = command.toLowerCase();
  21. if (command.equals("create"))
  22. {
  23. boolean exitCreate = false;
  24. while (exitCreate == false)
  25. {
  26. System.out.println("Enter a username: ");
  27. String inputUser = in.nextLine();
  28. System.out.println("Enter a password PIN: ");
  29. int inputPass = in.nextInt();
  30.  
  31. if (accountNum < 33)
  32. {
  33. AccountData[accountNum] = new Account(inputUser, inputPass, false);
  34. System.out.println("Account Number " + accountNum + " created!");
  35. accountNum++;
  36. exitCreate = true;
  37. }
  38. else
  39. {
  40. System.out.println("Max Account Capacity");
  41. exitCreate = true;
  42. }
  43. }
  44. }
  45. else if (command.equals("login"))
  46. {
  47. System.out.println("Enter your username: ");
  48. String username = in.nextLine();
  49. System.out.println("Enter your password PIN: ");
  50. int password = in.nextInt();
  51. int search = 0;
  52. boolean exitLogin = false;
  53. while (exitLogin == false && search <= accountNum)
  54. {
  55. if(username.equals(AccountData[search].username) && password == AccountData[search].password && AccountData[search].admin == true)
  56. {
  57. System.out.println("Create Admin (create), Delete Account (delete), or Print?");
  58. while(exitLogin == false && search <= accountNum)
  59. {
  60.  
  61. String option = in.nextLine();
  62. if(option.equals("create"))
  63. {
  64. System.out.println("Enter an admin username: ");
  65. String inputUser1 = in.nextLine();
  66. System.out.println("Enter a password PIN: ");
  67. int inputPass1 = in.nextInt();
  68.  
  69. if (accountNum < 33)
  70. {
  71. AccountData[accountNum] = new Account(inputUser1, inputPass1, true);
  72. System.out.println("Account Number " + accountNum + " created!");
  73. accountNum++;
  74. exitLogin = true;
  75. }
  76. else
  77. {
  78. System.out.println("Max Account Capacity");
  79. exitLogin = true;
  80. }
  81. }
  82. else if(option.equals("delete"))
  83. {
  84. System.out.println("Type the number for the account you want to remove:");
  85. int remove = in.nextInt();
  86. AccountData[remove] = new Account("", 0 , false);
  87. System.out.println("Successfully Removed.");
  88. exitLogin = true;
  89. }
  90. else if(option.equals("print"))
  91. {
  92. System.out.println("Usernames:" + AccountData[search].username);
  93. System.out.println("Passcodes:" + AccountData[search].password);
  94. exitLogin = true;
  95.  
  96. }
  97. }
  98. }
  99. else if (username.equals(AccountData[search].username) && (password == AccountData[search].password && AccountData[search].admin == false))
  100. {
  101. System.out.println("Successful!");
  102. exitLogin = true;
  103. exitMain = true;
  104. }
  105. else if (!username.equals(AccountData[search].username) && (password != AccountData[search].password))
  106. {
  107. System.out.println("Login Failed.");
  108. exitLogin = true;
  109. }
  110.  
  111. search++;
  112. }
  113. }
  114. else if (command.equals("exit"))
  115. {
  116. System.out.println("Program will now exit.");
  117. exitMain = true;
  118. }
  119. }
  120. in.close();
  121. }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement