From 3cb45f48ffd59af641a53afc940e8930877f6b00 Mon Sep 17 00:00:00 2001 From: Dannylui58 <143028255+Dannylui58@users.noreply.github.com> Date: Mon, 29 Apr 2024 22:19:56 -0700 Subject: [PATCH] Update APCalendar.java --- src/main/java/APCalendar.java | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/APCalendar.java b/src/main/java/APCalendar.java index 46a3aa8..ff6d5da 100644 --- a/src/main/java/APCalendar.java +++ b/src/main/java/APCalendar.java @@ -1,3 +1,4 @@ + public class APCalendar { /** Returns true if year is a leap year and false otherwise. */ @@ -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; } @@ -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; } }