//
// Created by Julio Tentor <[email protected]>
//
import java.text.SimpleDateFormat;
import java.util.Date;
enum SexType {
Mujer,
Varon;
}
public class Person implements Comparable<Person> {
protected String firstName;
protected String lastName;
protected SexType sex;
protected Date birthDate;
protected String homeAddress;
public String getFirstName() {
return this.firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return this.lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public SexType getSex() {
return this.sex;
}
public void setSex(SexType sex) {
this.sex = sex;
}
public Date getBirthDate() {
return this.birthDate;
}
public void setBirthDate(Date birthDate) {
this.birthDate = birthDate;
}
public Integer getAge() {
if (this.getBirthDate() != null) {
return (new Date()).getYear() - this.getBirthDate().getYear();
}
return 0;
}
public String getHomeAddress() {
return this.homeAddress;
}
public void setHomeAddress(String homeAddress) {
this.homeAddress = homeAddress;
}
public Person() {
this("John", "Doe", SexType.Varon, new Date(), "no home address");
}
public Person(String firstName, String lastName, SexType sex, Date birthDate, String homeAddress) {
setFirstName(firstName);
setLastName(lastName);
setSex(sex);
setBirthDate(birthDate);
setHomeAddress(homeAddress);
}
protected final static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/YYYY");
@Override
public String toString() {
return "Person{" +
"nombre='" + getFirstName() + '\'' +
", apellido='" + getLastName() + '\'' +
", sexo=" + getSex() +
", fecha de nacimiento=" + Person.simpleDateFormat.format( getBirthDate() ) +
", edad=" + getAge() +
", domicilio='" + getHomeAddress() + '\'' +
'}';
}
@Override
public int compareTo(Person o) {
return (getLastName() + getFirstName()).compareTo(o.getLastName() + o.getFirstName());
}
// public int compareTo(Person o) {
// return getAge().compareTo(o.getAge());
// }
}
Comments