Advertisement
Guest User

Person Class

a guest
Nov 21st, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.05 KB | None | 0 0
  1. public class Person implements Comparable<Person>{
  2.     private String name;
  3.     private int age;
  4.     private String address;
  5.  
  6.     Person() {
  7.  
  8.     }
  9.  
  10.     Person(String name, int age, String address) {
  11.         this.name = name;
  12.         this.age = age;
  13.         this.address = address;
  14.     }
  15.  
  16.     public String getName() {
  17.         return name;
  18.     }
  19.  
  20.     public int getAge() {
  21.         return age;
  22.     }
  23.  
  24.     public String getAddress() {
  25.         return address;
  26.     }
  27.  
  28.     public void setAddress(String address) {
  29.         this.address = address;
  30.     }
  31.  
  32.     public void setAge(int age) {
  33.         this.age = age;
  34.     }
  35.  
  36.     public void setName(String name) {
  37.         this.name = name;
  38.     }
  39.  
  40.     @Override
  41.     public int compareTo(Person person) {
  42.         if (this.getName().compareTo(person.getName()) != 0)
  43.             return this.getName().compareTo(person.getName());
  44.         else
  45.             if (this.getAge() > person.getAge()) return 1;
  46.             else if (this.getAge() < person.getAge()) return -1;
  47.             return 0;
  48.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement