Key points

  • Calling methods ; in this case a return method
  • If statement

Scoring Guidelines

a.

  • +1 Initializes a numeric variable
  • +1 Loops through each necessary year in the range
  • +1 Calls isLeapYear on some valid year in the range
  • +1 Updates count based on result of calling isLeapYear
  • +1 Returns count of leap year

b.

  • +1 Calls firstDayOfYear
  • +1 Calls dayOfYear
  • +1 Calculates the value representing the day of the week
  • +1 Returns the calculated value

Write the static method numberOfLeapYears, which returns the number of leap years between year1 and year2, inclusive.

public static int numberOfLeapYears(int year 1, int year 2)
{
    int count = 0
    for ( int i = year 1 <= year 2; i++)
    { 
      if (isLeapYear(i))
        {
            count++; 
        }
    }
    
    return count;

}

Write the static method dayOfWeek, which returns the integer value representing the day of the week for the given date (month, day, year), where 0 denotes Sunday, 1 denotes Monday, ..., and 6 denotes Saturday.

public static int dayOfWeek(int month, int day, int year){
    int firstDay = firstDayOfYear(year);
    int nDay = dayOfYear(month, day, year);
    int returnDay = (firstDay + nDay - 1) % 7;
    return returnDay;
}