import java.awt.Color;
import java.util.*;
import hsa.Console;

public class Birthday_calc
{
    public static void main (String[] args)
    {
	Console c = new Console ();
	int i;
	String[] thing = {
	    "year",
	    "month",
	    "date"
	    };

	String[] day = {
	    "Sunday",
	    "Monday",
	    "Tuesday",
	    "Wednesday",
	    "Thursday",
	    "Friday",
	    "Saturday"
	    };

	int[] limit = new int [12];
	for (i = 0 ; i < limit.length ; i++)
	    limit [i] = 31;
	int[] thirty = {3, 5, 8, 10};
	for (i = 0 ; i < thirty.length ; i++)
	    limit [thirty [i]] = 30;

	int[] param = new int [3];
	long elapsed = 0;
	String dayabbr, temp;

	while (elapsed != -1)
	{
	    for (i = 0 ; i < param.length ; i++)
	    {
		c.print ("Enter birth " + thing [i] + ": ", 19);
		while (true)
		{
		    temp = c.readLine ();
		    try
		    {
			param [i] = Integer.parseInt (temp);
			if (i == 0 || i == 2 && param [i] >= 1 && param [i] <= limit [param [1] - 1])
			    break;
			else if (i == 1 && param [i] >= 1 && param [i] <= 12)
			{
			    if (param [i] == 2)
				if (param [0] % 4 == 0)
				    limit [1] = 29;
				else
				    limit [1] = 28;
			    break;
			}
			else
			{
			    c.setTextColor (Color.blue);
			    c.print ("Out of range. Retry: ");
			    c.setTextColor (Color.black);
			}
		    }
		    catch (NumberFormatException nfe)
		    {
			c.setTextColor (Color.red);
			c.print ("Not integer. Retry: ");
			c.setTextColor (Color.black);
		    }
		}
	    }

	    GregorianCalendar gc = new GregorianCalendar (param [0], param [1] - 1, param [2]);
	    elapsed = System.currentTimeMillis () - gc.getTimeInMillis ();
	    c.println ("You are " + ((double) elapsed / 86400000) + " days old.\nYou were born on a " + day [gc.get (Calendar.DAY_OF_WEEK) - 1] + ".\n");
	}
    }
}
