Advertisement
dizzy94

27.People

May 20th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 KB | None | 0 0
  1. public class People implements Comparable<People>{
  2.     private String imie;
  3.     private String nazwisko;
  4.     private int wiek;
  5.    
  6.     public int getWiek() {
  7.         return wiek;
  8.     }
  9.  
  10.     public void setWiek(int wiek) {
  11.         this.wiek = wiek;
  12.     }
  13.  
  14.     People(String imie, String nazwisko, int wiek){
  15.         this.imie = imie;
  16.         this.nazwisko = nazwisko;
  17.         this.wiek = wiek;
  18.     }
  19.    
  20.     public String getImie() {
  21.         return imie;
  22.     }
  23.     public void setImie(String imie) {
  24.         this.imie = imie;
  25.     }
  26.    
  27.     public String getNazwisko() {
  28.         return nazwisko;
  29.     }
  30.    
  31.     public void setNazwisko(String nazwisko) {
  32.         this.nazwisko = nazwisko;
  33.     }
  34.  
  35.     @Override
  36.     public int compareTo(People o) {
  37.         if(this.wiek == o.wiek){
  38.             return 0;
  39.         }
  40.         else if(this.wiek > o.wiek){
  41.             return 1;  
  42.         }
  43.         else{
  44.             return -1; 
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement