Advertisement
jtentor

LinkedList 2da parte - Person.java

Oct 23rd, 2021
783
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.53 KB | None | 0 0
  1. //
  2. // Created by Julio Tentor <jtentor@fi.unju.edu.ar>
  3. //
  4.  
  5. import java.text.SimpleDateFormat;
  6. import java.util.Date;
  7.  
  8. enum SexType {
  9.     Mujer,
  10.     Varon;
  11. }
  12.  
  13. public class Person implements Comparable<Person> {
  14.  
  15.     protected String firstName;
  16.     protected String lastName;
  17.     protected SexType sex;
  18.     protected Date birthDate;
  19.     protected String homeAddress;
  20.  
  21.  
  22.     public String getFirstName() {
  23.         return this.firstName;
  24.     }
  25.     public void setFirstName(String firstName) {
  26.         this.firstName = firstName;
  27.     }
  28.  
  29.     public String getLastName() {
  30.         return this.lastName;
  31.     }
  32.     public void setLastName(String lastName) {
  33.         this.lastName = lastName;
  34.     }
  35.  
  36.     public SexType getSex() {
  37.         return this.sex;
  38.     }
  39.     public void setSex(SexType sex) {
  40.         this.sex = sex;
  41.     }
  42.  
  43.     public Date getBirthDate() {
  44.         return this.birthDate;
  45.     }
  46.     public void setBirthDate(Date birthDate) {
  47.         this.birthDate = birthDate;
  48.     }
  49.     public Integer getAge() {
  50.         if (this.getBirthDate() != null) {
  51.             return (new Date()).getYear() - this.getBirthDate().getYear();
  52.         }
  53.         return 0;
  54.     }
  55.  
  56.     public String getHomeAddress() {
  57.         return this.homeAddress;
  58.     }
  59.     public void setHomeAddress(String homeAddress) {
  60.         this.homeAddress = homeAddress;
  61.     }
  62.  
  63.     public Person() {
  64.         this("John", "Doe", SexType.Varon, new Date(), "no home address");
  65.     }
  66.     public Person(String firstName, String lastName, SexType sex, Date birthDate, String homeAddress) {
  67.         setFirstName(firstName);
  68.         setLastName(lastName);
  69.         setSex(sex);
  70.         setBirthDate(birthDate);
  71.         setHomeAddress(homeAddress);
  72.     }
  73.  
  74.     protected final static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/YYYY");
  75.  
  76.     @Override
  77.     public String toString() {
  78.         return "Person{" +
  79.                 "nombre='" + getFirstName() + '\'' +
  80.                 ", apellido='" + getLastName() + '\'' +
  81.                 ", sexo=" + getSex() +
  82.                 ", fecha de nacimiento=" + Person.simpleDateFormat.format( getBirthDate() ) +
  83.                 ", edad=" + getAge() +
  84.                 ", domicilio='" + getHomeAddress() + '\'' +
  85.                 '}';
  86.     }
  87.  
  88.     @Override
  89.     public int compareTo(Person o) {
  90.         return (getLastName() + getFirstName()).compareTo(o.getLastName() + o.getFirstName());
  91.     }
  92. //    public int compareTo(Person o) {
  93. //        return getAge().compareTo(o.getAge());
  94. //    }
  95. }
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement