Advertisement
jtentor

DemoList5 - Person.java

Jun 8th, 2020
1,417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1. // Created by Julio Tentor <jtentor@fi.unju.edu.ar>
  2. //
  3. import java.lang.Comparable;
  4.  
  5. public class Person implements Comparable<Person> {
  6.     private String lastname;
  7.     private String firstname;
  8.  
  9.     public Person() {
  10.         this("", "");
  11.     }
  12.     public Person(String lastname, String firstname) {
  13.         this.lastname = lastname;
  14.         this.firstname = firstname;
  15.     }
  16.  
  17.     @Override
  18.     public String toString() {
  19.         return this.lastname +  ", " + this.firstname;
  20.     }
  21.  
  22.     @Override
  23.     public int compareTo(Person o) {
  24.         return this.toString().compareTo(o.toString());
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement