I am looking to display the date by using the calendar object.
public abstract class Employee implements EmployeeInfo {
protected String firstName;
protected String lastName;
protected String idNumber;
Calendar birthday = Calendar.getInstance();
protected char gender;
public Employee()
{
firstName = "";
lastName = "";
idNumber = "";
gender = ' ';
birthday.set(Calendar.MONTH, 0);
birthday.set(Calendar.DAY_OF_MONTH, 00);
birthday.set(Calendar.YEAR, 0000);
}
public Employee(String first, String last, String id, char gen, int month, int day, int year)
{
firstName = first;
lastName = last;
idNumber = id;
gender = gen;
birthday.set(Calendar.MONTH, month);
birthday.set(Calendar.DAY_OF_MONTH, day);
birthday.set(Calendar.YEAR, year);
}
public Calendar getBirthday() {
return birthday;
}
public void setBirthday(int month, int day, int year, Calendar birthday) throws ParseException {
birthday = Calendar.getInstance();
birthday.set(Calendar.MONTH, month);
birthday.set(Calendar.DAY_OF_MONTH, day);
birthday.set(Calendar.YEAR, year);
SimpleDateFormat formatted = new SimpleDateFormat("MM/dd/yyyy");
String date = month + "/" + day + "/" + year;
Date birth = formatted.parse(date);
birthday.setTime(birth);
this.birthday = birthday;
}
public String toSring()
{
return "ID Employee Number: " + idNumber + "\n" + "Employee name: " + firstName + " "
+ lastName + "\n" + "Birth date: " + birthday + "\n";
}
public abstract double getMonthlyEarning();
public class Staff extends Employee {
protected double hourlyRate;
public Staff()
{
super();
hourlyRate = 0.0;
}
public Staff(String first, String last, String ID, char gen1, int month, int day, int year, double rate)
{
super(first, last, ID, gen1, month, day, year);
hourlyRate = rate;
}
}
…and…
public class Test {
public static void main(String[] args) {
Employee[] employees = new Employee[2];
employees[0] = new Staff("Minh", "Vu", "123", 'M', 3,06,1997, 50.00);
employees[1] = new Staff("Mike", "Nguyen", "456", 'M', 5,18,1977, 65.00);
for(Employee member : employees)
{
System.out.println(member);
System.out.println("------------------------------------------");
}
}
}
The problem I am facing is why the birth date in the following output gives me an unknown, ridiculously long line:
ID Employee Number: 123
Employee name: Minh Vu
Birth date: java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="America/Los_Angeles",offset=-28800000,dstSavings=3600000,useDaylight=true,transitions=185,lastRule=java.util.SimpleTimeZone[id=America/Los_Angeles,offset=-28800000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=1997,MONTH=3,WEEK_OF_YEAR=6,WEEK_OF_MONTH=2,DAY_OF_MONTH=6,DAY_OF_YEAR=37,DAY_OF_WEEK=2,DAY_OF_WEEK_IN_MONTH=1,AM_PM=1,HOUR=2,HOUR_OF_DAY=0,MINUTE=0,SECOND=0,MILLISECOND=0,ZONE_OFFSET=-28800000,DST_OFFSET=0]
Full Time
Monthly Salary: $8000.0
ID Employee Number: 456
Employee name: Mike Nguyen
Birth date: java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="America/Los_Angeles",offset=-28800000,dstSavings=3600000,useDaylight=true,transitions=185,lastRule=java.util.SimpleTimeZone[id=America/Los_Angeles,offset=-28800000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=1977,MONTH=5,WEEK_OF_YEAR=6,WEEK_OF_MONTH=2,DAY_OF_MONTH=18,DAY_OF_YEAR=37,DAY_OF_WEEK=2,DAY_OF_WEEK_IN_MONTH=1,AM_PM=1,HOUR=2,HOUR_OF_DAY=0,MINUTE=0,SECOND=0,MILLISECOND=0,ZONE_OFFSET=-28800000,DST_OFFSET=0]
Full Time
Monthly Salary: $10400.0
Based on my analysis, I believe that I have to use create an object from the SimpleDateFormat class and put "MM/dd/yyyy" into the parameter. However, I have to parse the SimpleDateFormat object by creating a Date object. I would like to use the Calendar class to create my date object.
When I was debugging, I noticed that the display of the birth date was wrong; it printed everything within my birthday object. I'm not sure what to do. The help would be greatly appreciated. :)