AP® Computer Science A
Free-Respon Questions
© 2019 The College Board. College Board, Advanced Placement, AP, AP Central, and the acorn logo are
registered trademarks of the College Board. Visit the College Board on the web: collegeboard.
AP Central is the official online home for the AP Program: .
COMPUTER SCIENCE A
SECTION II
Time — 1 hour and 30 minutes
Number of questions —4
Percent of total score —50
Directions: SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA.
Notes:
• Assume that the interface and class listed in the Java Quick Reference have been imported where appropriate.
• Unless otherwi noted in the question, assume that parameters in method calls are not null and that methods are called only when their preconditions are satisfied.
• In writing solutions公证委托书模板 for each question, you may u any of the执子之手什么意思 accessible methods that are listed in class defined in that question. Writing significant amounts of code that can be replaced by a call to one of the methods will not receive full credit.
© 2019 The 腿无力是什么原因College Board.
Visit the College Board on the web: collegeboard.
GO ON TO THE NEXT PAGE.
-2-
1. The APCalendar class contains methods ud to calculate information about a calendar. You will write two methods of the class.
public class APCalendar
{
/** Returns true if year is a leap year and fal otherwi. */
袁隆平作文素材
private static boolean isLeapYear(int year)
{ /* implementation 海南省大学排名not shown */ }
/** Returns the number of leap years世界第一大党 between year1 and year2, inclusive.
* Precondition: 0 <= year1 <= year2
*/
public static int numberOfLeapYears(int year1, int year2)
{ /* to be implemented in part (a) */ }
/** Returns the value reprenting the day of the week for the first day of在乎近义词 year, * where 0 denotes Sunday, 1 denotes Monday, ..., and 6 denotes Saturday. */
private static int firstDayOfYear(int year)
{面试步骤 /* implementation not shown */ }
/** Returns n, where month, day, and year specify the nth day of the year. * Returns 1 for January 1 (month = 1, day = 1) of any year. * Precondition: The date reprented by month, day, year is a valid date. */
private static int dayOfYear(int month, int day, int year)
{ /* implementation not shown */ }
/** Returns the value reprenting the day of the week for the given date
* (month, day, year), where 0 denotes Sunday, 1 denotes Monday, ...,
* and 6 denotes Saturday.
* Precondition: The date reprented by month, day, year is a valid date. */
public static int dayOfWeek(int month, int day, int year)
{ /* to be implemented in part (b) */ }
// There may be instance variables, constructors, and other methods not shown. }