Here is the driver:

// Test driver to use the MyDate class to calculate the day of the year // and day of the week for a date given as year (as NNNN), month (as 1-12) // and a day (1-31) of month import java.util.*; import java.text.SimpleDateFormat; public class FindDay2 { // Main method gets date as input, creates a MyDate object, and calls // methods to determine day of year and day of week. public static void main(String[] args) { // Prompt the user for month, day, and year Scanner input = new Scanner(System.in); System.out.print("Enter a date as month(1-12), day(1-31), year (" + MyDate.YEAR_FIRST + "-" + MyDate.YEAR_LAST + "): " ); int month = input.nextInt(); int day = input.nextInt(); int year = input.nextInt(); // Create a MyDate object and check that it is a valid date MyDate mydate = new MyDate(month, day, year); if (!mydate.isValidDate()) { System.out.println("Invalid date: " + mydate); System.exit(1); } // Calculate the day number in the year int dayOfYear = mydate.getDayOfYear(); // Calculate the day of the week String dayOfWeek = mydate.getDayOfWeek(); System.out.println(mydate + " is day number " + dayOfYear + " of the year" + " which is a " + dayOfWeek); // Use Java library classes to check our results Calendar calendar = new GregorianCalendar(year, month-1, day); SimpleDateFormat formatter = new SimpleDateFormat("EEE, MMM d, yyyy 'is day number' D 'of the year'"); System.out.println("Java: " + formatter.format(calendar.getTime())); } }

and here is the code that I have written for the MyDate class:

/** * @(#)MyDate.java * * * @author * @version 1.00 2011/2/1 */ public class MyDate { private int month, day, year; public static int YEAR_FIRST = 1600, YEAR_LAST = 2400; //the constructor of the MyDate object. public MyDate(int month, int day, int year) { this.month = month; this.day = day; this.year = year; } // if the date the user enters is a valid date, then it returns true // otherwise, it returns false. public boolean isValidDate(){ if(this.month < 1 || this.month > 12) return false; if(this.year < 1600 || this.year > 2400) return false; // minimum number of days is 1 // max number of days is 31 if(this.day < 1 || this.day > 31) return false; if(this.month == 2){ //if the month is February, check for a leap year if(isLeapYear()){ if(this.day > 29) return false; }else{ if(this.day > 28) return false; } } // if the month is April, June, September, or November, it can have a max of 30 days if(this.month == 3 || this.month == 6 || this.month == 9 || this.month == 11){ if(day > 30) return false; } return true; } // check if the year is a leap year public boolean isLeapYear(){ if(this.year % 4 == 0 || ( this.year % 100 == 0 && this.year % 400 != 0)){ return true; }else{ return false; } } public int getDayOfYear(){ // if the month is january, // no special checking needed. if(this.month == 1) return this.day; // if the month is February // just return 31 plus the number of days if(this.month == 2) return this.day + 31; int totalDays = 0; // add 31 for every month up to the current month for(int i = 1; i < this.month; i++){ totalDays += 31; } // check for months that only have 30 days in them // and subtract 1 for each month that only has 30 days for(int i = 1; i < this.month; i++){ if(i == 3 || i == 6 || i ==9 || i == 11) totalDays -= 1; } // check if leap year, and that the month of February is past // if leap year, subtract 2 days, otherwise subtract 3 days if(isLeapYear() && this.month > 2){ totalDays -= 2; }else{ totalDays -= 3; } // at the current month, add the total number of // days into the month totalDays += this.day; // return days :D/> return totalDays; } // get the day of the week public String getDayOfWeek(){ double totalDays = 0; int firstDay = 1; for(int i = 1600; i < this.year; i++){ totalDays += 365; firstDay += 1; if(firstDay == 8)firstDay = 1; if(this.year % 4 == 0 || ( this.year % 100 == 0 && this.year % 400 != 0)){ totalDays += 1; firstDay += 1; if(firstDay == 8)firstDay = 1; } } totalDays += getDayOfYear(); int today = (int) totalDays % firstDay; String thisDay = ""; switch(today){ case 0: thisDay = "Saturday"; break; case 1: thisDay = "Sunday"; break; case 2: thisDay = "Monday"; break; case 3: thisDay = "Tuesday"; break; case 4: thisDay = "Wednesday"; break; case 5: thisDay = "Thursday"; break; case 6: thisDay = "Friday"; break; default: thisDay = ""; break; } return thisDay; } // converts the object into a string public String toString(){ return this.month + "/" + this.day + "/" + this.year; } }

Any help is greatly appreciated.