Guest User

Untitled

a guest
Jul 12th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 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. do {
  10. System.out.println("What would you like to do? Type 1 to register or 2"
  11. + " to login.");
  12. regLogin = key.nextInt();
  13. while (regLogin == 1 || regLogin == 2) {
  14. if (regLogin == 1) {
  15. System.out.println("Enter username(10-20 characters): ");
  16. String username = "";
  17. boolean isValid = true;
  18. do {
  19. if (!isValid) {
  20. System.out.println("Username invalid or already exists."
  21. + " Re-enter:");
  22. }
  23. username = key.nextLine();
  24. } while (!(isValid = SecondLifeAccount2.goodUsername(username)
  25. && SecondLifeAccount2.existingUsername(username)));
  26. System.out.println("Username accepted.");
  27.  
  28. System.out.println("Enter password(6-16 characters, 1 uppercase"
  29. + ", 1 lowercase, 1 digit): ");
  30. String password = "";
  31. do {
  32. if (!isValid) {
  33. System.out.println("Password invalid. Re-enter:");
  34. }
  35. password = key.nextLine();
  36. } while (!(isValid = SecondLifeAccount2.goodPassword(password)));
  37. System.out.println("Password accepted.");
  38.  
  39. System.out.println("Enter secret question: ");
  40. String secretQuestion = key.nextLine();
  41. System.out.println("Enter secret answer: ");
  42. String secretAnswer = key.nextLine();
  43. System.out.println("Enter date of birth: ");
  44. int dob;
  45. do {
  46. if (!isValid) {
  47. System.out.println("Date of birth invalid. Re-enter:");
  48. }
  49. dob = key.nextInt();
  50. } while (!(isValid = SecondLifeAccount2.goodDob(dob)));
  51. System.out.println("Date of birth accepted.");
  52.  
  53. SecondLifeAccount2 user1 = new SecondLifeAccount2(username,
  54. password, dob, secretQuestion, secretAnswer);
  55.  
  56. System.out.println("Account created!");
  57. System.out.println("Username: " + user1.getUsername());
  58. System.out.println("Password: " + user1.getPassword());
  59. System.out.println("Date of birth: " + user1.getDob());
  60. System.out.println("Secret question: "
  61. + user1.getSecretQuestion());
  62. System.out.println("Secret answer: " + user1.getSecretAnswer());
  63. SecondLifeAccount2.saveToFile(user1);
  64. break;
  65. }
  66.  
  67. if (regLogin == 2 && SecondLifeAccount2.existingAccount == true) {
  68. System.out.println("Welcome back!");
  69. break;
  70. }
  71. System.out.println("Please type 1 or 2.");
  72. }
  73. }while (regLogin > 2);
  74. }
  75. }
Add Comment
Please, Sign In to add comment