Advertisement
Guest User

Untitled

a guest
Oct 10th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. import java.util.*;
  2. public class Main
  3. {
  4. public static void main(String [ ] args)
  5. {
  6. // System variables
  7. Scanner keyboard = new Scanner(System.in);
  8.  
  9. // Normal variables
  10. String firstname = "";
  11. String surname = "";
  12. String password = "";
  13. String[] passwordArray = new String[] {password};
  14. String username = "";
  15. String email = "";
  16. String company = "";
  17.  
  18. int passwordLength = 0;
  19. int amountOfNumbers = 0;
  20.  
  21. // Getting nesseccary inputs
  22. System.out.print("Please enter first name : ");
  23. firstname = keyboard.nextLine();
  24. System.out.print("Please enter surname : ");
  25. surname = keyboard.nextLine();
  26. System.out.print("Please enter password : ");
  27. password = keyboard.nextLine();
  28. System.out.print("Please enter your company : ");
  29. company = keyboard.nextLine();
  30.  
  31.  
  32. username = firstname.toLowerCase() + "." + surname.toLowerCase();
  33.  
  34. passwordLength = passwordArray.length;
  35.  
  36. email = username + "@" + company + ".com";
  37.  
  38.  
  39. System.out.print("Please enter password : ");
  40. password = keyboard.nextLine();
  41.  
  42. // Splits the password into an array and checks each one to see if it is a number or not.
  43.  
  44. char[] passwordArray = password.split("").toCharArray();
  45.  
  46. passwordLength = passwordArray.length;
  47.  
  48.  
  49. // Program iterates over all array elements at once
  50. for (char character : passwordArray)
  51. {
  52. if (Character.isDigit(character))
  53. {
  54. amountOfNumbers++;
  55. }
  56. else
  57. {
  58. return;
  59. }
  60. }
  61.  
  62. // Checks if the password has at least 8 characters, and there is at least 2 numbers
  63. while (passwordLength < 8 || amountOfNumbers < 2) {
  64. if (passwordLength < 8)
  65. {
  66. System.out.println("Your password is not long enough.");
  67. } else {
  68. if(amountOfNumbers < 2) {
  69. System.out.println("You don't have enough numbers.");
  70. }
  71. }
  72. }
  73.  
  74. // Prints out the nesseccary outputs in the right format.
  75. System.out.println("username is : " + username);
  76. System.out.println("Your password has " + passwordLength + " characters");
  77. System.out.println("Your email is : " + email);
  78.  
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement