Advertisement
Guest User

AccountLogin Lab - 1-10-17 | 2:26 pm

a guest
Jan 10th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. package jan6;
  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. Scanner in = new Scanner(System.in);
  10. int exit = 0; // To exit loop
  11. int accountNumCheck = 0;
  12. int exitLogin = 0;
  13. while (exit == 0)
  14. {
  15. System.out.println("Enter 'create' to create an account, 'login' to login to your account or 'exit' to close. ");
  16. String command = in.nextLine(); // Command input
  17. command = command.toLowerCase();
  18.  
  19. int accountNum = 0; // Initialize counter
  20. if (command.equals("create")) // CREATE ACCOUNT
  21. {
  22. System.out.println("Enter a username: ");
  23. String inputUser = in.nextLine();
  24. System.out.println("Enter a numeric password: ");
  25. int inputPass = in.nextInt();
  26. AccountData[accountNum] = new Account(inputUser, inputPass);
  27. accountNum++;
  28. System.out.println("This is your username: " + AccountData[0].username);
  29. System.out.println("This is your password: " + AccountData[0].password);
  30. }
  31. else if (command.equals("login")) // LOGIN TO ACCOUNT
  32. {
  33. System.out.println("Enter your username: ");
  34. String loginUser = in.nextLine();
  35. System.out.println("Enter your password: ");
  36. int loginPass = in.nextInt();
  37.  
  38. while (exitLogin == 0)
  39. {
  40. if (accountNumCheck > 33)
  41. {
  42. System.out.println("Account doesn't exist. Exitting program.");
  43. exit++;
  44. exitLogin++;
  45. }
  46. if (loginUser.equals(AccountData[accountNumCheck].username) && loginPass == AccountData[accountNumCheck].password)
  47. {
  48. System.out.println("Welcome. \nProgram will now exit.");
  49. exit++;
  50. exitLogin++;
  51. }
  52. else
  53. {
  54. accountNumCheck++;
  55. }
  56. }
  57. }
  58. else if (command.equals("exit")) // EXIT PROGRAM
  59. {
  60. System.out.println("End Program");
  61. exit++;
  62. }
  63. }
  64. in.close();
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement