Advertisement
sergAccount

Untitled

Sep 5th, 2020
1,229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package com.spec.model;
  7.  
  8. /**
  9.  *
  10.  * @author Admin
  11.  */
  12. public class Person implements Comparable<Person>{
  13.    
  14.     private String name; //
  15.     private int age;
  16.  
  17.     public Person(String name, int age) {
  18.         this.name = name;
  19.         this.age = age;
  20.     }
  21.  
  22.     public String getName() {
  23.         return name;
  24.     }
  25.  
  26.     public void setName(String name) {
  27.         this.name = name;
  28.     }
  29.  
  30.     public int getAge() {
  31.         return age;
  32.     }
  33.  
  34.     public void setAge(int age) {
  35.         this.age = age;
  36.     }
  37.    
  38.     // compareTo - сравниваем два объекта по имени
  39.     @Override
  40.     public int compareTo(Person o) {
  41.        
  42.         return getName().compareTo(o.getName());
  43.     }
  44. }
  45.  
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement