Guest User

Untitled

a guest
Mar 2nd, 2017
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 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 *** ");
  13.  
  14.  
  15. System.out.print("\n\n");
  16.  
  17. //FIRSTNAME
  18. System.out.print("First Name: \t");
  19. String firstname = input.nextLine();
  20.  
  21. //LASTNAME
  22. System.out.print("Last Name: \t");
  23. String lastname = input.nextLine();
  24.  
  25. //ADDRESS
  26. System.out.print("Home Address: \t");
  27. String add = input.nextLine();
  28.  
  29. //POSTAL CODE
  30. System.out.print("Postal Code: \t");
  31. int PC = input.nextInt();
  32. while (PC < 1000 || PC > 2991 ) {
  33. System.out.print("Postal code not found. Please try again ");
  34. PC = input.nextInt();
  35. }
  36.  
  37. //PHONE NUMBER
  38. System.out.print("Phone Number: \t");
  39.  
  40. //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
  41. String test = input.nextLine();
  42. String number = input.nextLine();
  43. while (number.length() != 8) {
  44. System.out.print("Telephone number should be 8 digits. Please try again ");
  45. number = input.nextLine();
  46. }
  47.  
  48.  
  49. //CPR NUMBER
  50. System.out.print("CPR-Number: \t");
  51. String cpr = input.nextLine();
  52. char dash = cpr.charAt(6);
  53. while (cpr.length() != 11 && dash !='-') {
  54. System.out.print("Error, use format XXXXXX-XXXX, please try again ");
  55. cpr = input.nextLine();
  56. }
  57.  
  58.  
  59. System.out.print("\n\n\n");
  60.  
  61. //USERNAME
  62. String s1 = firstname.substring(0,1);
  63. String s2 = lastname.substring(0,3);
  64. String username = s1 + s2;
  65. System.out.println("Your username is: " + username);
  66.  
  67. //PASSWORD
  68. String s3 = lastname.substring(0,3);
  69. String s4 = cpr.substring(7, 11);
  70. String password = s3 + s4;
  71. System.out.println("Your password is: " + password);
  72.  
  73. //LOG-IN PROMPT
  74. System.out.println("if you would like to EXIT, please type 1 and enter");
  75. System.out.println("If you would like to LOG-IN, please type 2 and enter");
  76. String command = input.nextLine();
  77.  
  78. System.out.println("\n");
  79.  
  80. switch (command) {
  81. case "1": System.out.print("You have now exited. Goodbye!"); break;
  82. case "2": System.out.println("Please enter username below");
  83. }
  84.  
  85. System.out.println("\n");
  86.  
  87. // LOG-IN
  88. System.out.println("Enter Username");
  89. String loginusername = input.nextLine();
  90. while (!loginusername.equals(username)) {
  91. System.out.println("Username not found, try again");
  92. loginusername = input.next();
  93. }
  94.  
  95. System.out.println("Enter Password");
  96. String userpassword = input.nextLine();
  97. while (!userpassword.equals(password)) {
  98. System.out.println("Wrong Password, try again");
  99. userpassword = input.next();
  100. }
  101.  
  102.  
  103. System.out.println("You are now logged in!");
  104.  
  105.  
  106.  
  107.  
  108. }
  109.  
  110. }
Add Comment
Please, Sign In to add comment