Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 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.  
  23. //LASTNAME
  24. System.out.print("Last Name: \t");
  25. String lastname = input.nextLine();
  26.  
  27. //ADDRESS
  28. System.out.print("Street name: \t");
  29. String sn = input.nextLine();
  30.  
  31. System.out.print("Street number (and block or floor if relevant) \t");
  32. String st = input.nextLine();
  33.  
  34.  
  35. //POSTAL CODE
  36. System.out.print("Postal Code: \t");
  37. int PC = input.nextInt();
  38. while (PC < 1000 || PC > 2991 ) {
  39. System.out.print("Postal code not found in Copenhagen region. Please try again ");
  40. PC = input.nextInt();
  41. }
  42.  
  43. //PHONE NUMBER
  44. System.out.print("Phone Number: \t");
  45.  
  46. //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
  47. String test = input.nextLine();
  48. String number = input.nextLine();
  49. while (number.length() != 8) {
  50. System.out.print("Telephone number should be 8 digits. Please try again ");
  51. number = input.nextLine();
  52. }
  53.  
  54.  
  55. //CPR NUMBER
  56. System.out.print("CPR-Number: \t");
  57. String cpr = input.nextLine();
  58. char dash = cpr.charAt(6);
  59. while (cpr.length() != 11 && dash !='-') {
  60. System.out.print("Error, use format XXXXXX-XXXX, please try again ");
  61. cpr = input.nextLine();
  62. }
  63.  
  64.  
  65. System.out.println("\n\nUser creation complete!\n");
  66.  
  67. //USERNAME
  68. String s1 = firstname.substring(0,1);
  69. String s2 = lastname.substring(0,3);
  70. String username = s1 + s2;
  71. System.out.println("Your username is: " + username);
  72.  
  73. //PASSWORD
  74. String s3 = lastname.substring(0,3);
  75. String s4 = cpr.substring(7, 11);
  76. String password = s3 + s4;
  77. System.out.println("Your password is: " + password);
  78.  
  79. System.out.println("\n");
  80.  
  81. //LOG-IN PROMPT
  82. System.out.println("To EXIT, please type 1 and enter \n");
  83. System.out.println("To LOG-IN, please type 2 and enter \n");
  84. String command = input.nextLine();
  85.  
  86. System.out.println("\n");
  87.  
  88. switch (command) {
  89. case "1": System.out.print("You have now exited. Goodbye!"); break;
  90. case "2": System.out.println("Please enter username below \n");
  91. }
  92.  
  93.  
  94. // LOG-IN
  95. {
  96. System.out.println("Enter Username");
  97. String loginusername = input.nextLine();
  98. while (!loginusername.equals(username))
  99. {
  100. System.out.println("Username not found, try again");
  101. loginusername = input.next();
  102. }
  103.  
  104.  
  105. System.out.println("Enter Password");
  106. String userpassword = input.nextLine();
  107. int count = 3;
  108. while (!userpassword.equals(password)) {
  109. count--;
  110. System.out.println("Wrong Password, you have " + count + " attempts left");
  111. if (count==0) {
  112. System.out.print("Sorry you have exceeded the number of tries. Please try again after few hours");
  113. System.exit(0);
  114. }
  115. userpassword = input.next();
  116. }
  117. }
  118.  
  119. System.out.println("You are now logged in!");
  120.  
  121.  
  122.  
  123.  
  124. }
  125.  
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement