Necesito ingresar una fecha que tenga día, mes y año, por teclado, utilizando la clase Calendar, cual método llamo, de esta clase.
Este es el código:
package models;
import java.util.Calendar;
public class User{
protected EnumGenderUser gender;
protected Calendar birthDate;
protected String password;
protected EnumCountry country;
protected String email;
public User (EnumGenderUser gender, Calendar birthDate, String password, EnumCountry country, String email){
this.setGender(gender);
this.setBirthDate(birthDate);
this.setPassword(password);
this.setCountry(country);
this.setEmail(email);
}
@Override
public String toString(){
return super.toString();
}
//--------------------------------Setters------------------------------------------
public void setGender(EnumGenderUser gender){
this.gender = gender;
}
public void setBirthDate(Calendar birthDate){
this.birthDate = birthDate;
}
public void setPassword(String password){
this.password = password;
}
public void setCountry(EnumCountry country){
this.country = country;
}
public void setEmail(String email){
this.email = email;
}
//--------------------------------Getters------------------------------------------
public EnumGenderUser getGender(){
return this.gender;
}
public Calendar getBirthDate(){
return this.birthDate;
}
public String getPassword(){
return this.password;
}
public EnumCountry getCountry(){
return this.country;
}
public String getEmail(){
return this.email;
}
}
Aquí la clase Hija:
package models;
import java.util.Calendar;
public class Admin extends User{
private String name;
private String occupation;
private int id;
public Admin(String name, String occupation, int id, EnumGenderUser gender, Calendar birthDate, String password, EnumCountry country, String email){
super(gender, birthDate, password, country, email);
this.setName(name);
this.setOccupation(occupation);
this.setId(id);
}
@Override
public String toString(){
String formatLine = "%1$-20s %2$-15s %3$-10s %4$-9s %5$-9s %6$-10s %7$-10s %8-30s";
String adminLine = String.format(formatLine, name, occupation, id, gender, birthDate, password, country, email);
return adminLine;
}
//--------------------------------Setters------------------------------------------
public void setName(String name){
this.name = name;
}
public void setOccupation(String occupation){
this.occupation = occupation;
}
public void setId(int id){
this.id = id;
}
//--------------------------------Getters------------------------------------------
public String getName(){
return this.name;
}
public String getOccupation(){
return this.occupation;
}
public int getId(){
return this.id;
}
}
Los Enumerados: package models;
public enum EnumGenderUser{
FEMENINO, MASCULINO;
}
package models;
public enum EnumCountry{
COLOMBIA, VENEZUELA, ARGENINA, CHILE, ECUADOR;
}
y el test:
package test;
import models.Admin;
import models.EnumCountry;
import models.EnumGenderUser;
import java.util.Calendar;
public class TestModels{
public static void main(String[] args){
Admin adminObj = new Admin("Juan", "Diseñador", 64335, EnumGenderUser.MASCULINO, calendar.set(1990, 04, 12), "Qwerty123", EnumCountry.COLOMBIA, "[email protected]");
System.out.println(adminObj.toString());
}
}
Calendar
posea internamente una fecha como "2016-09-03" y luego puedas imprimirla o algo por el estilo?Date
) y luego puedes pasar este objetoDate
aCalendar
.