Guest User

Untitled

a guest
Mar 14th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class UserAccount {
  4.  
  5. private static final String DOMAIN = "ics.hawaii.edu";
  6. private String fName;
  7. private String firstName;
  8. private String lastName;
  9. private String init = "";
  10. private String username;
  11. private String email;
  12. private String password = "";
  13.  
  14.  
  15. public UserAccount(String fullname) {
  16. this.fName = fullname;
  17. this.firstName = getFirstName();
  18. this.lastName = getLastName();
  19. //this.initials = getInitials();
  20. this.username = getUsername();
  21. this.email = getEmailAddress();
  22. this.password = getPassword();
  23.  
  24. }
  25.  
  26. public String getFullName() {
  27. return fName;
  28. }
  29.  
  30.  
  31. public String getFirstName() {
  32.  
  33. int endOfFirstName = this.fName.indexOf(' ');
  34. String firstName = this.fName.substring(0, endOfFirstName);
  35. return firstName;
  36. }
  37.  
  38. public String getLastName() {
  39.  
  40. int startOfLastName = this.fName.lastIndexOf(" ") + 1;
  41. lastName = this.fName.substring(startOfLastName);
  42. return lastName;
  43. }
  44.  
  45. public String getInitials() {
  46. Scanner scan = new Scanner(this.getFullName());
  47. while (scan.hasNext()) {
  48. init += scan.next().substring(0,1);
  49. }return init.toUpperCase();
  50. }
  51.  
  52. public String getUsername() {
  53. username = this.firstName.substring(0,1);
  54. username = username + this.getLastName();
  55. username.toLowerCase();
  56. return username;
  57. }
  58.  
  59. public String getEmailAddress() {
  60. email = this.getUsername() + "@" + getDomain();
  61. return email;
  62. }
  63.  
  64. public String getPassword() {
  65.  
  66. if (this.password.length() == 0) {
  67. for (int x = 1; x < 8; x++) {
  68. int random = (int) (Math.random() * (10 + 26 + 26));
  69. if (random < 10) { //add a digit
  70. password += random;
  71. } else if (random < 36) { //add an uppercase letter
  72. password += (char) ('A' + (random - 10));
  73. } else { //add lowercase
  74. password += (char) ('a' + (random - 36));
  75. }
  76. } return this.password;
  77. } return this.password;
  78. }
  79.  
  80. public boolean setPassword(String newPassword) {
  81.  
  82. this.password = newPassword;
  83. for (int i=0; i < this.password.length(); i++) {
  84. if (!Character.isLetterOrDigit(this.password.charAt(i))) {
  85. return false;
  86. }
  87. } return true;
  88.  
  89. }
  90.  
  91. public static String getDomain() {
  92. return DOMAIN;
  93. }
  94.  
  95. }
Add Comment
Please, Sign In to add comment