Guest User

Untitled

a guest
Mar 3rd, 2017
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. package Assignments;
  2. import java.util.Scanner;
  3.  
  4.  
  5. public class Shern {
  6.  
  7. public static void main(String[] args) {
  8. Scanner input = new Scanner(System.in);
  9.  
  10. // Welcome Logo
  11. System.out.println("\n");
  12. System.out.println(" *** C B S W E B S H O P *** \n\n");
  13.  
  14. System.out.println("Create User");
  15.  
  16.  
  17. System.out.print("\n\n");
  18.  
  19. //FIRSTNAME
  20. System.out.print("First Name: \t");
  21. String firstname = input.nextLine();
  22. String illegal = "0";
  23. while (firstname.contains(illegal)) {
  24. System.out.println("cannot contain numbers, try again");
  25. firstname = input.nextLine();
  26. }
  27.  
  28. //LASTNAME
  29. System.out.print("Last Name: \t");
  30. String lastname = input.nextLine();
  31.  
  32. //ADDRESS
  33. System.out.print("Street name: \t");
  34. String sn = input.nextLine();
  35.  
  36. System.out.print("Street number (and block or floor if relevant) \t");
  37. String st = input.nextLine();
  38.  
  39.  
  40. //POSTAL CODE
  41. System.out.print("Postal Code: \t");
  42. int PC = input.nextInt();
  43. while (PC < 1000 || PC > 2991 ) {
  44. System.out.print("Postal code not found in Copenhagen region. Please try again ");
  45. PC = input.nextInt();
  46. }
  47.  
  48. //PHONE NUMBER
  49. System.out.print("Phone Number: \t");
  50.  
  51. //I Insert the following code of line due to issues with next line addressed here http://stackoverflow.com/questions/13102045/scanner-is-skipping-nextline-after-using-next-nextint-or-other-nextfoo
  52. String test = input.nextLine();
  53. String number = input.nextLine();
  54. while (number.length() != 8) {
  55. System.out.print("Telephone number should be 8 digits. Please try again ");
  56. number = input.nextLine();
  57. }
  58.  
  59.  
  60. //CPR NUMBER
  61. System.out.print("CPR-Number: \t");
  62. String cpr = input.nextLine();
  63. char dash = cpr.charAt(6);
  64. while (cpr.length() != 11 && dash !='-') {
  65. System.out.print("Error, use format XXXXXX-XXXX, please try again ");
  66. cpr = input.nextLine();
  67. }
  68.  
  69.  
  70. System.out.println("\n\nUser creation complete!\n");
  71.  
  72. //USERNAME
  73. String s1 = firstname.substring(0,1);
  74. String s2 = lastname.substring(0,3);
  75. String username = s1 + s2;
  76. System.out.println("Your username is: " + username);
  77.  
  78. //PASSWORD
  79. String s3 = lastname.substring(0,3);
  80. String s4 = cpr.substring(7, 11);
  81. String password = s3 + s4;
  82. System.out.println("Your password is: " + password);
  83.  
  84. System.out.println("\n");
  85.  
  86. //LOG-IN PROMPT
  87. System.out.println("To EXIT, please type 1 and enter \n");
  88. System.out.println("To LOG-IN, please type 2 and enter \n");
  89. String command = input.nextLine();
  90.  
  91. System.out.println("\n");
  92.  
  93. switch (command) {
  94. case "1": System.out.print("You have now exited. Goodbye!"); break;
  95. case "2": System.out.println("Please enter username below \n");
  96. }
  97.  
  98.  
  99. // LOG-IN
  100. System.out.println("Enter Username");
  101. String loginusername = input.nextLine();
  102. System.out.println("Enter Password");
  103. String loginpassword = input.nextLine();
  104.  
  105. int attempt = 3;
  106. while ((!loginusername.equals(username)) || (!loginpassword.equals(password))) {
  107. attempt--;
  108. System.out.println("You pressed wrong password and/or username, you have " + attempt + " attempts left");
  109.  
  110. if (attempt == 0)
  111.  
  112. System.out.println("Sorry you have exceeded the number of tries. Please try again after few hours" );
  113.  
  114. else
  115. System.out.println("Enter Username");
  116. loginusername = input.next();
  117. System.out.println("Enter Password");
  118. loginpassword = input.next();
  119. }
  120.  
  121.  
  122.  
  123. if ((loginusername.equals(username)) && (loginpassword.equals(password))) {
  124. System.out.println("You are now logged in...");
  125. System.exit(0);
  126. }
  127.  
  128.  
  129.  
  130.  
  131. }
  132.  
  133. }
Add Comment
Please, Sign In to add comment