-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.java
More file actions
43 lines (37 loc) · 1.33 KB
/
User.java
File metadata and controls
43 lines (37 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package discussionboard;
import java.util.StringTokenizer;
public class User {
// instance varibales
private String name;
private String user;
// constructor for setting the instance varibales
public User(String fullName, String userName) {
if (fullName == null || fullName.trim().isEmpty()) {
throw new IllegalArgumentException("Full name cannot be blank.");
}
// take first word of the fullname when username field is empty
if (userName.trim().isEmpty()) {
String delimiters = " "; // blank space
// check if no username is enetered
if (userName.isEmpty()) {
// only takes first word in the full name string for username
StringTokenizer nameFull = new StringTokenizer(fullName, delimiters);
userName = nameFull.nextToken().toLowerCase();
} else {
// only take the first word entered for username
String[] inputString = userName.split(delimiters);
userName = inputString[0].toLowerCase();
}
}
name = fullName;
user = userName;
}
// getter for full name
public String getFullName() {
return name;
}
// getter for user name
public String getUserName() {
return user;
}
}