Skip to content

Commit

Permalink
Update APCalendar.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Dannylui58 authored Apr 30, 2024
1 parent 1c21e6d commit 3cb45f4
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/main/java/APCalendar.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

public class APCalendar
{
/** Returns true if year is a leap year and false otherwise. */
Expand All @@ -12,7 +13,11 @@ private static boolean isLeapYear(int year)
*/
public static int numberOfLeapYears(int year1, int year2)
{
/* to be implemented in part (a) */
int sum = 0;
for(int i = year1; i <= year2; i++)
if(isLeapYear(i))
sum++;
return sum;

}

Expand Down Expand Up @@ -51,6 +56,17 @@ 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 dayOfTheYear = dayOfYear(month, day, year);
int firstDayOfTheYear = firstDayOfYear(year);
int days = firstDayOfTheYear;
for (int i = 1; i < dayOfTheYear; i++)
{
days++;
if (days == 7)
{
days = 0;
}
}
return days;
}
}

0 comments on commit 3cb45f4

Please sign in to comment.