import java.util.*; import java.text.*; /** * This class will tell how old someone is. * You must set the variables manually for now :(. * But hey, it looks pretty! * @author Christopher Villareal 904420181 * @version 19 October 2007 */ public class Age { /** * The following creates a GregorianCalendar. * It is then parsed to look pretty and then spits out how * old you are in years with horrible decimal point * calculation. * @return Your Birthday and Age. */ public static void main(String[] args) { //uses 24 hour clock ;) GregorianCalendar date = new GregorianCalendar(1986, Calendar.JANUARY, 13, 8, 14); System.out.println("This is what your birthday looks like before nice parsing: " + date); // date.set(Calendar.DAY_OF_MONTH, 13); // date.set(Calendar.YEAR, 1986); // date.set(Calendar.January); // date.set(Calendar.HOUR, 8); // date.set(Calendar.MINUTE, 14); Date d = date.getTime(); DateFormat nice = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); String birthday = nice.format(d); System.out.println("Your birthday is " + birthday); //well 21 is gone...nothing to look forward too....oh! 25, insurance drops woot! long t1 = date.getTimeInMillis(); // System.out.println(t1); GregorianCalendar date2 = new GregorianCalendar(); double a = 31688764600.0; //did you know how many Milliseconds are in a year? well know you know. double t2 = date2.getTimeInMillis(); double age = Math.abs((t2 - t1) / a); //change from milli to years, because that many numbers would make anybody feel old! // System.out.println(t2); System.out.println("You are approximately " + age + " years old today!"); System.out.println("Please ignore the decimal points, I can't code math, hence the 'approximately' ;)"); //and know I want to have fun, remove this later or maybe not... GregorianCalendar date3 = new GregorianCalendar(2011, Calendar.JANUARY, 13, 8, 14); double t3 = date3.getTimeInMillis(); double wait = Math.abs((t3-t2) / a); System.out.println("You have " + wait + " more years to go before you're insurance finally drops when you turn 25!"); //oh I can't wait... } }