×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: abdul qayyum
Added: Aug 13, 2015 12:10 AM
Views: 10
Tags: no tags
File_1
  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 training1;
  7.  
  8. import javafx.beans.property.SimpleIntegerProperty;
  9. import javafx.beans.property.SimpleStringProperty;
  10. import javafx.beans.property.StringProperty;
  11.  
  12. /**
  13.  *
  14.  * @author USER
  15.  */
  16. public class Person implements Comparable<Person> {
  17.     private StringProperty firstName = new SimpleStringProperty();
  18.     private StringProperty lastName = new SimpleStringProperty();
  19.    
  20.     public Person(){
  21.         this.firstName.set("unknown");
  22.         this.lastName.set("unknown");
  23.     }
  24.    
  25.     public Person(String firstName,String lastName){
  26.         this.firstName.set(firstName);
  27.         this.lastName.set(lastName);
  28.     }
  29.    
  30.     public StringProperty firstNameProperty(){
  31.         return firstName;
  32.     }
  33.    
  34.     public final void setFirstName(String firstName){
  35.         this.firstName.set(firstName);
  36.     }
  37.    
  38.     public final String getFirstName(){
  39.         return firstName.get();
  40.     }
  41.    
  42.     public StringProperty lastNameProperty(){
  43.         return lastName;
  44.     }
  45.    
  46.     public final void setLastName(String lastName){
  47.         this.lastName.set(lastName);
  48.     }
  49.    
  50.     public final String getLastName(){
  51.         return lastName.get();
  52.     }
  53.    
  54.     @Override
  55.     public int compareTo(Person o) {
  56.         int diff = this.getFirstName().compareTo(o.getFirstName());
  57.         if(diff == 0){
  58.             diff = this.getLastName().compareTo(o.getLastName());
  59.         }
  60.         return diff;
  61.     }  
  62.  
  63.     @Override
  64.     public String toString() {
  65.         return this.getFirstName()+" "+this.getLastName();
  66.     }
  67.    
  68.    
  69. }
  70.