Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class UserAccount {
- private static final String DOMAIN = "ics.hawaii.edu";
- private String fName;
- private String firstName;
- private String lastName;
- private String init = "";
- private String username;
- private String email;
- private String password = "";
- public UserAccount(String fullname) {
- this.fName = fullname;
- this.firstName = getFirstName();
- this.lastName = getLastName();
- //this.initials = getInitials();
- this.username = getUsername();
- this.email = getEmailAddress();
- this.password = getPassword();
- }
- public String getFullName() {
- return fName;
- }
- public String getFirstName() {
- int endOfFirstName = this.fName.indexOf(' ');
- String firstName = this.fName.substring(0, endOfFirstName);
- return firstName;
- }
- public String getLastName() {
- int startOfLastName = this.fName.lastIndexOf(" ") + 1;
- lastName = this.fName.substring(startOfLastName);
- return lastName;
- }
- public String getInitials() {
- Scanner scan = new Scanner(this.getFullName());
- while (scan.hasNext()) {
- init += scan.next().substring(0,1);
- }return init.toUpperCase();
- }
- public String getUsername() {
- username = this.firstName.substring(0,1);
- username = username + this.getLastName();
- username.toLowerCase();
- return username;
- }
- public String getEmailAddress() {
- email = this.getUsername() + "@" + getDomain();
- return email;
- }
- public String getPassword() {
- if (this.password.length() == 0) {
- for (int x = 1; x < 8; x++) {
- int random = (int) (Math.random() * (10 + 26 + 26));
- if (random < 10) { //add a digit
- password += random;
- } else if (random < 36) { //add an uppercase letter
- password += (char) ('A' + (random - 10));
- } else { //add lowercase
- password += (char) ('a' + (random - 36));
- }
- } return this.password;
- } return this.password;
- }
- public boolean setPassword(String newPassword) {
- this.password = newPassword;
- for (int i=0; i < this.password.length(); i++) {
- if (!Character.isLetterOrDigit(this.password.charAt(i))) {
- return false;
- }
- } return true;
- }
- public static String getDomain() {
- return DOMAIN;
- }
- }
Add Comment
Please, Sign In to add comment