Created
December 15, 2015 03:28
-
-
Save jononon/1f794bfd008483ae4f3d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Name implements Comparable { | |
| private String first, last; | |
| public Name (String firstName, String lastName) { | |
| first = firstName; | |
| last = lastName; | |
| } | |
| public int compareTo(Object obj) { | |
| Name other = (Name) obj; | |
| if(other.toString().equals(this.toString())) | |
| return 0; | |
| else if (other.last == this.last) | |
| return this.first.compareTo(other.first); | |
| else | |
| return this.last.compareTo(other.last); | |
| } | |
| public String toString() { | |
| return first+" "+last; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment