Friday, 15 April 2011

calendar - Adding a Birthday to my Employee class java -



calendar - Adding a Birthday to my Employee class java -

i'm sure @ point when first learning programming create kind of programme teaches interfaces, abstracts, , polymorphism. well, that's i'm trying right now.

i'm coding in java, , i'm trying create abstract employee class. i'm running in 1 little problem though. want add together birthday employee, i'm not sure how calendar.

i able store birthday employees name i.e. public string employeename;. creating variable allow me utilize getters , setters on it.

the employee constructor this:

public employee(string name, int idnumber, string gender, int year, int month, int day)

to sum how create birthday variable using calendar, , if wanted birthday date(whatever set to) how that? give thanks you.

perhaps way go:

// declare birthday date: private date birthday; public employee(string name, int idnumber, string gender, int year, int month, int day) { this.name = name; this.idnumber = idnumber; this.gender = gender; initbirthday(year, month, day); } private void initbirthday(int year, int month, int day) { // int should greater 0 if (year > 0 && month > 0 && day > 0) { calendar cal = calendar.getinstance(); cal.set(year, month-1 , day, 0, 0, 0); // or explicit way // cal.set(calendar.year, year); // cal.set(calendar.month, month - 1); // jan == 0 !!!! // cal.set(calendar.day_of_month, day); // cal.set(calendar.hour,0); // cal.set(calendar.minute,0); // cal.set(calendar.second,0); birthday = cal.gettime(); // returns date } else { // set birthday default value... } }

java calendar

No comments:

Post a Comment