Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Person implements Comparable<Person>{
- private String name;
- private int age;
- private String address;
- Person() {
- }
- Person(String name, int age, String address) {
- this.name = name;
- this.age = age;
- this.address = address;
- }
- public String getName() {
- return name;
- }
- public int getAge() {
- return age;
- }
- public String getAddress() {
- return address;
- }
- public void setAddress(String address) {
- this.address = address;
- }
- public void setAge(int age) {
- this.age = age;
- }
- public void setName(String name) {
- this.name = name;
- }
- @Override
- public int compareTo(Person person) {
- if (this.getName().compareTo(person.getName()) != 0)
- return this.getName().compareTo(person.getName());
- else
- if (this.getAge() > person.getAge()) return 1;
- else if (this.getAge() < person.getAge()) return -1;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement