Question
public static int calculateWeekDay( int month, int year){ int weekdayOnFirstDayOfYear = calculateWeekdayOnFirstDayOfYear (year); int dayOfYear = calculateDayOfYearOnFirstOfMonth (month, year); //If Jan 1 falls on a
public static int calculateWeekDay(int month, int year){
int weekdayOnFirstDayOfYear = calculateWeekdayOnFirstDayOfYear(year);
int dayOfYear = calculateDayOfYearOnFirstOfMonth(month, year);
//If Jan 1 falls on a sunday, weekdayOnFirstDayOfYear = 0 for sunday
//and since Jan 1 is first day of year, its dayofyear = 1
//When the method calculateWeekDay is queried for Jan 1, this method should return 0 (for sunday)
//So, we need to do -1 on dayOfYear's value (1 - 2 + 0) % 7 = 0 % 7 = 0
int weekDay = (dayOfYear - 1 + weekdayOnFirstDayOfYear)%7;
if(DEBUG) System.out.println("In calculateWeekDay: weekday: " + weekDay);
return weekDay;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started