birthdate class
I need to know how to prompt the user for their birth date and calculate and display how many days old they are. Can anyone help me out, because i am completely stuck, thanks in advance.
[186 byte] By [
oribit] at [2007-11-11 10:00:28]

# 4 Re: birthdate class
import java.util.Calendar;
import java.util.GregorianCalendar;
public class AgeCalculator {
public static void main(String[] args) {
int dob_date = 7;
int dob_month = 7;
int dob_year = 1979;
// Create a calendar object with the DOB
Calendar dob = new GregorianCalendar(dob_year, dob_month, dob_date);
// Create a calendar object with today's date
Calendar today = Calendar.getInstance();
int diff_year = (today.get(Calendar.YEAR) - dob.get(Calendar.YEAR));
int diff_month = (today.get(Calendar.MONTH) + 1) - dob.get(Calendar.MONTH);
int diff_date = (today.get(Calendar.DATE) - dob.get(Calendar.DATE));
int age = 0;
if(diff_year > 0){
age = diff_year;
if(diff_month < 0) age = age - 1;
else if(diff_month == 0){
if(diff_date < 0) age = age - 1;
}
}
System.out.println("Age : " + age);
}
}
fenoyf at 2007-11-11 22:35:04 >
