Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.58 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("gagandeep", 12345, true);
  15. int loginNumber = 1;
  16. while (account == false)
  17. {
  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 input = in.nextLine();
  64. if(input.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 adminPassword = in.nextInt();
  70.  
  71. if (loginNumber < 33)
  72. {
  73. AccountData[loginNumber] = new Account2(adminUser, adminPassword, 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 more admins can be made fool");
  81. login = true;
  82. }
  83. }
  84. else if (input.equals("delete"))
  85. {
  86. System.out.println("What account number would you like to delete?");
  87. int remove = in.nextInt();
  88. int z = loginNumber;
  89. for(int i = 0; i < loginNumber - (remove + 1) ;i++)
  90. {
  91. AccountData[z-2] = AccountData[z-1];
  92. z--;
  93. }
  94. AccountData[loginNumber-1] = AccountData[loginNumber];
  95. System.out.println("Successfully Removed.");
  96. loginNumber--;
  97. login = true;
  98. }
  99. else if(input.equals("print"))
  100. {
  101. for(int i = 0; i <= loginNumber; i++)
  102. {
  103. System.out.println("Username: " + AccountData[i].username);
  104. System.out.println("Password: " + AccountData[i].password);
  105. }
  106.  
  107. }
  108. }
  109.  
  110.  
  111. }
  112. else if (username.equals(AccountData[array].username) && (password == AccountData[array].password) && AccountData[array].admin == false)
  113. {
  114. System.out.println("BOSSSSS YOU MADE IT...now the code finna quit");
  115. login = true;
  116. account = true;
  117. }
  118. else
  119. {
  120. System.out.println("Login didn't work");
  121. }
  122. array++;
  123. }
  124. }
  125. else if (enter.equals("quit"))
  126. {
  127. System.out.println("Program will now quit");
  128. account = true;
  129. }
  130. }
  131.  
  132. }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement