Reference: https://apcentral.collegeboard.org/media/pdf/ap23-frq-comp-sci-a.pdf
Topics:
for loops
conditions
black-box functions
A Blackbox function is a function where you're not told how it works, you're simply told that it works. It's like asking a friend to solve a puzzle, they then put the puzzle inside a box, solve the problem without you seeing it, then bring it back out completed. How did they do it? Doesn't matter - it's done, and it's (hopefully) correct.
This would be a good problem for 2D arrays (if having students solve the problem without the Helper code below) or Object Creation (if the Helper code below is already provided). This problem might be better saved for AP Prep, when students have a solid grasp of problem solving and code understanding.
Correctly understand the purpose of each function (those you create and those created for you).
isMinuteFree - Blackbox Function - only checks if a single minute within the schedule is free (not if an entire block is free).
reserveBlock - Blackbox Function - sets all minutes within a period & range to "not available".
findFreeBlock - checks all minutes within a period (0-59) to find a span large enough for the duration being sought and that is available. If such a span exists, it returns the first minute of that span. If it doesn't exist, it returns -1. Must use the isMinuteFree function (which you should assume works).
makeAppointment - searches through all periods (inclusively between 2 provided course numbers) for a block of available time (using the findFreeBlock function), and if it finds one, it sets them as no longer available (using the reserveBlock function) and returns true. Otherwise, it returns false.
Assume the AppointmentBook has a 2D array instance variable that keeps track of availability.
Each row is a course (row 0 represents course 1, row 7 represents course 8)
Each row contains the #'s 0-59, representing each minute of an hour.
Assume you'll never need to directly access this 2D array from the functions you create. Also, assume any course/row offsets will occur in the hidden functions.
*** With so much hidden code, it can be easy to feel overwhelmed by the problem, but these 2 portions of the problem are pretty easy. Use loops, conditions, and the "black-box functions" provided in this object to help you solve the problem.
Test code is not usually provided, but this problem can be difficult to understand how to solve without some sort of test code. Try solving the problems on paper prior to solving on a computer with this test code.