-
Notifications
You must be signed in to change notification settings - Fork 0
/
FullName.java
37 lines (29 loc) · 1.05 KB
/
FullName.java
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
package com.company2;
/**
* Created by Benjamin R. on 02-08-2016.
*/
public class FullName implements Comparable<FullName> {
private final String firstName;
private final String lastName;
public FullName( String f, String l ) {
firstName= f;
lastName= l;
}
public String getFirstName() {return firstName;}
public String getLastName() {return lastName;}
public int compareTo( FullName fn ) {
// Complete the compareTo() method
// Order by last name first
int result = 0;
if(lastName.length() < fn.lastName.length()) { result = -1;}
if(lastName.length() > fn.lastName.length()) { result = 1; }
if(lastName.length() == fn.lastName.length()) {
if(firstName.length() < fn.firstName.length()){result = -1;} else
if(firstName.length() > fn.firstName.length()){result = 1; }
else result = 0;}
return result;
}
public String toString() {
return firstName + " " + lastName;
}
}