Advertisement
Guest User

Untitled

a guest
Jan 26th, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.83 KB | None | 0 0
  1. package arrays;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class AccountLogin2
  6. {
  7. static Account2[] AccountData = new Account2[33];
  8.  
  9. public static void main(String []args)
  10. {
  11. int error = 0;
  12. boolean account = false;
  13. Scanner in = new Scanner(System.in);
  14. AccountData[0] = new Account2("ggd", 1, true);
  15. while (account == false)
  16. {
  17. int loginNumber = 1;
  18. if (error % 2 == 0)
  19. {
  20. System.out.println("Would you like to create an account, login, or quit?");
  21. }
  22. error++;
  23. String enter = in.nextLine();
  24. enter = enter.toLowerCase();
  25. if (enter.equals("create"))
  26. {
  27. boolean create = false;
  28. while (create == false)
  29. {
  30. System.out.println("Enter a username: ");
  31. String user = in.nextLine();
  32. System.out.println("Enter a password: ");
  33. int pass = in.nextInt();
  34. if (loginNumber < 33)
  35. {
  36. AccountData[loginNumber] = new Account2(user, pass, false);
  37. loginNumber++;
  38. create = true;
  39. }
  40. else
  41. {
  42. System.out.println("No mo accounts can b made fool");
  43. create = true;
  44. }
  45. }
  46. }
  47. else if (enter.equals("login"))
  48. {
  49. System.out.println("Enter your username: ");
  50. String username = in.nextLine();
  51. System.out.println("Enter your password: ");
  52. int password = in.nextInt();
  53. int array = 0;
  54. boolean login = false;
  55. while (array <= loginNumber && login == false)
  56. {
  57. if(username.equals(AccountData[array].username) && password == AccountData[array].password && AccountData[array].admin == true)
  58. {
  59. System.out.println("Hello Admin, would you like to create another administrator, delete an account, or print an account?");
  60. while (array <= loginNumber && login == false)
  61. {
  62.  
  63. String option = in.nextLine();
  64. if (option.equals("create"))
  65. {
  66. System.out.println("Enter username for new admin: ");
  67. String adminUser = in.nextLine();
  68. System.out.println("Enter password for new admin: ");
  69. int adminPass = in.nextInt();
  70.  
  71. if (loginNumber < 33)
  72. {
  73. AccountData[loginNumber] = new Account2(adminUser, adminPass, true);
  74. System.out.println("Account number " + loginNumber + " has been created");
  75. loginNumber++;
  76. login = true;
  77. }
  78. else
  79. {
  80. System.out.println("No mo accounts can b made fool");
  81. login = true;
  82. }
  83. }
  84. else if(option.equals("delete"))
  85. {
  86. System.out.println("What account number would you like to delete?");
  87. int delete = in.nextInt();
  88. int arrayValue = loginNumber;
  89. for(int i = 0; i < loginNumber - (delete + 1); i++)
  90. {
  91. AccountData[arrayValue - 2] = AccountData[arrayValue - 1];
  92. arrayValue--;
  93. }
  94. AccountData[loginNumber - 1] = AccountData[loginNumber];
  95. System.out.println("Account number " + loginNumber + " has been deleted");
  96. loginNumber--;
  97. login = true;
  98. }
  99.  
  100. else if(option.equals("print"))
  101. {
  102. for(int i = 0; i <= loginNumber; i++)
  103. {
  104. System.out.println("Username: " + AccountData[i].username);
  105. System.out.println("Password: " + AccountData[i].password);
  106. }
  107.  
  108. login = true;
  109.  
  110. }
  111. }
  112.  
  113. }
  114. else if (username.equals(AccountData[array].username) && (password == AccountData[array].password && AccountData[array].admin == false))
  115. {
  116. System.out.println("Logging in...");
  117. login = true;
  118. account = true;
  119. }
  120. else if (!username.equals(AccountData[array].username) && (password != AccountData[array].password))
  121. {
  122. System.out.println("Login did not work...");
  123. login = true;
  124. }
  125.  
  126. array++;
  127. }
  128. }
  129.  
  130. else if (enter.equals("quit"))
  131. {
  132. System.out.println("Program will now exit.");
  133. account = true;
  134. }
  135. }
  136. }
  137.  
  138.  
  139.  
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement