Guest User

Untitled

a guest
Nov 30th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. import java.util.*;
  2. /**
  3. * Write a description of class strings here.
  4. *
  5. * @author (your name)
  6. * @version (a version number or a date)
  7. */
  8. public class strings
  9. {
  10. public static void main(String args[]){
  11. Scanner scan = new Scanner(System.in);
  12. System.out.println("Write your FULL name");
  13. String fullName = scan.nextLine();
  14. System.out.println("Write your 4 digit graduation year");
  15. String gradYear = scan.nextLine();
  16. int firstSpace = fullName.indexOf(" ");
  17. String firstName = fullName.substring(0,(firstSpace));
  18. String restOfName = fullName.substring(firstSpace + 1);
  19. int secondSpace = restOfName.indexOf(" ");
  20. //System.out.println("second space = " + secondSpace);
  21. int NamesNum = 0;
  22. String lastName;
  23. String middleName = "";
  24. String username = "";
  25. //System.out.println(firstName);
  26. if(secondSpace == -1){
  27. NamesNum = 2;
  28. lastName = restOfName;
  29. //System.out.println("1 space");
  30. }
  31. else{
  32. NamesNum = 3;
  33. //System.out.println(fullName.length());
  34. middleName = restOfName.substring(0,secondSpace);
  35. lastName = restOfName.substring(secondSpace+1);
  36. //System.out.println("2 spaces");
  37. }
  38. gradYear = gradYear.substring(2);
  39. //System.out.println(firstName);
  40. //System.out.println(middleName);
  41. //System.out.println(lastName);
  42. if(middleName.length() > 0 && lastName.length() > 3){
  43.  
  44. username = lastName.substring(0,4) + firstName.substring(0,1) + middleName.substring(0,1) + gradYear;
  45. }else if(lastName.length() > 3){
  46. username = lastName.substring(0,4) + firstName.substring(0,1) + gradYear;
  47. }else if(middleName.length() > 0){
  48. username = lastName + firstName.substring(0,1) + middleName.substring(0,1) + gradYear;
  49. }else{
  50. username = lastName + firstName.substring(0,1) + gradYear;
  51. }
  52. System.out.println(username);
  53. System.out.println("If you would like a password too, type 0");
  54. int x = scan.nextInt();
  55. if(x == 0){
  56. String letters = "abcdefghijklmnopqrstuvwxyz";
  57. String numbers = "0123456789";
  58. String spec = "!@#$%^&*?";
  59. int count = 0;
  60. int pick;
  61. int rand;
  62. String password = "Password: ";
  63. int lettersUsed = 0;
  64. int numbersUsed = 0;
  65. int specUsed = 0;
  66. int upperUsed = 0;
  67. while (count < 8){
  68. //(int)(Math.random() * ((max-min) + 1)) + min;
  69. pick = (int)(Math.random()*(3+1));
  70. if(pick == 0){
  71. lettersUsed++;
  72. rand = (int)(Math.random() * ((letters.length()-1-1) + 1)) + 1;
  73. password = password + letters.substring(rand-1, rand);
  74.  
  75. }else if(pick == 1){
  76. numbersUsed ++;
  77. rand = (int)(Math.random() * ((numbers.length()-1-1) + 1)) + 1;
  78. password = password + numbers.substring(rand-1, rand);
  79. }else if(pick == 2){
  80. specUsed ++;
  81. rand = (int)(Math.random() * ((spec.length()-1-1) + 1)) + 1;
  82. password = password + spec.substring(rand-1, rand);
  83. }else{
  84. upperUsed ++;
  85. rand = (int)(Math.random() * ((letters.length()-1-1) + 1)) + 1;
  86. password = password + (letters.substring(rand-1, rand)).toUpperCase();
  87. }
  88. count++;
  89. }
  90.  
  91. System.out.println(password);
  92. }
  93. }
  94. }
Add Comment
Please, Sign In to add comment