Advertisement
Guest User

person

a guest
Mar 21st, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 KB | None | 0 0
  1. package collection;
  2.  
  3. public class Person implements Comparable<Person>{
  4.  
  5.    
  6.     private int id;
  7.     private String name;
  8.    
  9.    
  10.     public static void printHello() {
  11.         System.out.println("hello");
  12.     }
  13.    
  14.    
  15.     public Person(int id, String name) {
  16.         super();
  17.         this.id = id;
  18.         this.name = name;
  19.     }
  20.     public int getId() {
  21.         return id;
  22.     }
  23.     public void setId(int id) {
  24.         this.id = id;
  25.     }
  26.     public String getName() {
  27.         return name;
  28.     }
  29.     public void setName(String name) {
  30.         this.name = name;
  31.     }
  32.     @Override
  33.     public String toString() {
  34.         return "Person [id=" + id + ", name=" + name + "]";
  35.     }
  36.    
  37.     @Override
  38.     public int compareTo(Person o) {
  39.        
  40.         if(this.id>o.getId()){
  41.             return 1;
  42.         }else if (this.id<o.getId()) {
  43.             return -1;
  44.         }else {
  45.             return 0;
  46.         }
  47.        
  48.        
  49.        
  50.     }
  51.    
  52.    
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement