Skip to content

Commit

Permalink
Update APCalendar.java
Browse files Browse the repository at this point in the history
  • Loading branch information
hyunjaeoh7 authored May 1, 2024
1 parent 6bc32e6 commit 8f95a4b
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/main/java/APCalendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@ private static boolean isLeapYear(int year)
*/
public static int numberOfLeapYears(int year1, int year2)
{
/* to be implemented in part (a) */

int count = 0;
count = (year2 - year1)/4;
if((year2-year1) % 4 > 0){
for(int i = 0; i < (year2-year1)%4; i++){
count++;
}
}
return count;

}

/** Returns the value representing the day of the week for the first day of year,
Expand Down Expand Up @@ -51,6 +58,11 @@ private static int dayOfYear(int month, int day, int year)
*/
public static int dayOfWeek(int month, int day, int year)
{
/* to be implemented in part (b) */
int day = firstDayOfYear(year);
int[] months = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
for(int i = 0; i < month; i++){
day += months[i];
}
return day % 7;
}
}

0 comments on commit 8f95a4b

Please sign in to comment.