Advertisement
Guest User

1

a guest
Sep 5th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. package one;
  2.  
  3. import java.util.Scanner;
  4.  
  5.  
  6. public class JavaBikes1 {
  7.  
  8. public static void main(String[] args) {
  9. // TODO Auto-generated method stub
  10.  
  11. System.out.println("WELCOME");
  12.  
  13. Scanner input = new Scanner(System.in);
  14.  
  15. System.out.println("Press 1 for \"login\" and 2 for \"create new account\"");
  16. int menuChoice = input.nextInt();
  17.  
  18. if (menuChoice == 2) {
  19.  
  20. System.out.print("Enter your first and last name: ");
  21. String name = input.nextLine();
  22.  
  23. System.out.print("Enter your postal code: ");
  24. int postCode = input.nextInt();
  25. while (postCode > 2501 || postCode < 1000) {
  26. System.out.println("Please enter a valid 4 digit postal code for the Copenhagen area: ");
  27. int postCodes = input.nextInt();
  28. }
  29.  
  30. System.out.print("Enter your phone number: ");
  31. int phoneNumber = input.nextInt();
  32. String phoneNumber1 = Integer.toString(phoneNumber);
  33. int length = phoneNumber1.length();
  34. while (length != 8) {
  35. System.out.println("Please enter a valid 8 digit phone number");
  36. phoneNumber = input.nextInt();
  37. }
  38.  
  39. System.out.print("Enter your date of birth (i.e. mm-dd-yyyy): ");
  40. String dateOfBirth = input.nextLine();
  41.  
  42. System.out.println("Enter your CPR (i.e. XXXXXX-XXXX): ");
  43. int cpr = input.nextInt();
  44. //while ( true ) {
  45. //int i = 0;
  46. //char digit = dateOfBirth.charAt(i);
  47. //Character.isDigit(digit);//
  48.  
  49.  
  50. String username = createUsername(name);
  51.  
  52. System.out.print("Enter your desired password (max 8 numbers): ");
  53. int password = input.nextInt();
  54.  
  55. System.out.println("Your username is " + username + " and your password is " + password);
  56.  
  57. }
  58.  
  59. else if (menuChoice == 1) {
  60. System.out.print("Enter your username: ");
  61. String usernameAttempt = input.nextLine();
  62. System.out.print("Enter your password: ");
  63. int passwordAttempt = input.nextInt();
  64. while (usernameAttempt != username || passwordAttempt != password) {
  65. System.out.print("Wrong username or password. Try again: ");
  66. System.out.print("Enter your username: ");
  67. usernameAttempt = input.nextLine();
  68. System.out.print("Enter your password: ");
  69. passwordAttempt = input.nextInt();
  70. }
  71. }
  72. }
  73.  
  74. // Creates method for generating username
  75. public static String createUsername(String name) {
  76. String[] parts = name.split(" ");
  77. String firstName = parts[0];
  78. String lastName = parts[1];
  79. int number = (int)(Math.random() * 101);
  80. //int lastName1 = Integer.parseInt(lastName);
  81. String username = "lastName" + "number";
  82. return username;
  83. }
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement