Guest User

AccountLogin Lab - 1-12-17 | 2:28 pm

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