Advertisement
Guest User

Untitled

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