Application Program Interface (API) and Libraries FRQ Practice

Responses receive AI feedback against a rubric after submission. Scores are practice estimates.

Question 1 of 5

A harbor project needs reusable classes for beacons, tides, and slips.

(a) Explain what a class library provides. (b) Explain what an API specification adds on top of just having class files. (c) Explain why related classes might be placed in the same package.

Question 2 of 5

Use only this LighthouseBeacon contract.

Member Kind Contract
rangeKm attribute int distance of the current beam
setRange method sets rangeKm to the given int value
dim method decreases rangeKm by 2, but not below 0
readRange method returns the current rangeKm

(a) Identify the attribute and state the type of data it stores. (b) Identify one behavior and describe what it does according to the table. (c) Explain why a client should not call a method named flare if it is absent from the table.

Question 3 of 5

A classmate says attributes and methods are the same because both belong to a class.

(a) Contrast attributes with behaviors. (b) State how each is represented in a class (variables versus methods). (c) Give one attribute and one behavior from everyday objects, not from a Java library you invent.

Question 4 of 5

A student opens ParcelLocker documentation before writing client code.

Member Kind Contract
occupied attribute boolean, true when a parcel is inside
store method sets occupied to true
release method sets occupied to false
isOccupied method returns occupied

(a) Explain why reading the API is a better first step than guessing from names alone. (b) After release is used on a locker whose occupied attribute is true, what does isOccupied return? (c) Explain whether the student may rely on a method named jamDoor.

Question 5 of 5

Using only the RecitalHall contract, seats starts at 3.

Member Kind Contract
seats attribute int remaining seats
hold method decreases seats by 1 if seats is positive
remaining method returns seats

(a) Describe the values of seats after hold is used once and after it is used three times total. (b) Explain what remaining returns after those three holds. (c) The theater wants to add 10 seats. Explain whether the documented API allows that update.