-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathName.java
More file actions
83 lines (69 loc) · 1.71 KB
/
Copy pathName.java
File metadata and controls
83 lines (69 loc) · 1.71 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
public class Name {
//Name instance variables
private String firstName;
private String middleName;
private String lastName;
public Name(String fName, String lName) {
firstName = fName;
middleName = "";
lastName = lName;
}
public Name(String fname,String mname,String lname) {
firstName = fname;
middleName = mname;
lastName = lname;
}
public Name (String fullName) {
int pos1 = fullName.indexOf(' ');
firstName = fullName.substring(0, pos1);
int pos2 = fullName.lastIndexOf(' ');
if (pos1 == pos2)
middleName = "";
else
middleName = fullName.substring(pos1+1, pos2);
lastName = fullName.substring(pos2 + 1);
}
public String getFirstName() {
return firstName;
}
public String getMiddleName() {
return middleName;
}
public String getLastName() {
return lastName;
}
public String getFirstAndLastName() {
return firstName + " " + lastName;
}
public String getLastCommaFirst() {
String result = "";
if(!middleName.equals("")) {
result = lastName + ", " +firstName + " " + middleName;
}
else {
result= lastName + ", " +firstName;
}
return result;
}
public String getInitials() {
String result = firstName.charAt(0) + "";
if (!middleName.equals("")) {
result += middleName.charAt(0);
}
result += lastName.charAt(0);
return result;
}
public String getFullName() {
String result = firstName + " ";
if (!middleName.equals("")) {
result += middleName + " ";
}
result += lastName;
return result;
}
public int compareTo(Name other) {
String thisName=lastName + " " + firstName + " " + middleName;
String othername = other.lastName+ " " + other.firstName + other.middleName;
return thisName.compareTo(othername);
}
}