Guest User

Untitled

a guest
Jul 12th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.83 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.util.Scanner;
  3.  
  4. public class SLAccount2Test {
  5.  
  6. public static void main(String[] args) throws IOException {
  7. Scanner key = new Scanner(System.in);
  8. int regLogin;
  9. String username = "";
  10. String password = "";
  11. do {
  12.  
  13. System.out.println("What would you like to do? Type 1 to register or 2"
  14. + " to login.");
  15. regLogin = key.nextInt();
  16. {
  17. if (regLogin == 1) {
  18. System.out.println("Enter username(10-20 characters): ");
  19. boolean isValid = true;
  20. do {
  21. if (!isValid) {
  22. System.out.println("Username invalid or already exists."
  23. + " Re-enter:");
  24. }
  25. username = key.nextLine();
  26. } while (!(isValid = SecondLifeAccount2.goodUsername(username)
  27. && SecondLifeAccount2.existingUsername(username)));
  28. System.out.println("Username accepted.");
  29.  
  30. System.out.println("Enter password(6-16 characters, 1 uppercase"
  31. + ", 1 lowercase, 1 digit): ");
  32. do {
  33. if (!isValid) {
  34. System.out.println("Password invalid. Re-enter:");
  35. }
  36. password = key.nextLine();
  37. } while (!(isValid = SecondLifeAccount2.goodPassword(password)));
  38. System.out.println("Password accepted.");
  39.  
  40. System.out.println("Enter secret question: ");
  41. String secretQuestion = key.nextLine();
  42. System.out.println("Enter secret answer: ");
  43. String secretAnswer = key.nextLine();
  44. System.out.println("Enter date of birth: ");
  45. int dob;
  46. do {
  47. if (!isValid) {
  48. System.out.println("Date of birth invalid. Re-enter:");
  49. }
  50. dob = key.nextInt();
  51. } while (!(isValid = SecondLifeAccount2.goodDob(dob)));
  52. System.out.println("Date of birth accepted.");
  53.  
  54. SecondLifeAccount2 user1 = new SecondLifeAccount2(username,
  55. password, dob, secretQuestion, secretAnswer);
  56.  
  57. System.out.println("Account created!");
  58. System.out.println("Username: " + user1.getUsername());
  59. System.out.println("Password: " + user1.getPassword());
  60. System.out.println("Date of birth: " + user1.getDob());
  61. System.out.println("Secret question: "
  62. + user1.getSecretQuestion());
  63. System.out.println("Secret answer: " + user1.getSecretAnswer());
  64. SecondLifeAccount2.saveToFile(user1);
  65. break;
  66. }
  67. if (regLogin == 2)
  68. System.out.println("Enter username: ");
  69. username = key.nextLine();
  70. System.out.println("Enter password: ");
  71. password = key.nextLine();
  72.  
  73. if (SecondLifeAccount2.existingAccount(username, password) == true) {
  74. System.out.println("Welcome back!");
  75. break;
  76. }
  77. if (!SecondLifeAccount2.existingAccount(username, password)) {
  78. System.out.println("Username and password don't exist.");
  79. break;
  80. }
  81. System.out.println("Please type 1 or 2.");
  82. }
  83. } while (regLogin > 2);
  84. }
  85. }
Add Comment
Please, Sign In to add comment