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 coastal lab installs a harbor software library.

(a) Explain the difference between a library and a single class. (b) Explain why an API specification is a contract. (c) Explain what it means that a class defines a reference type.

Question 2 of 5

Use only this TrailKiosk contract.

Member Kind Contract
mapsLeft attribute int number of printed trail maps
dispense method decreases mapsLeft by 1 if mapsLeft is positive
restock method adds the given int to mapsLeft
countMaps method returns mapsLeft

(a) Classify mapsLeft, restock, and countMaps as attribute or behavior. (b) mapsLeft starts at 4. restock is used with 2, then countMaps is used. State the returned value. (c) Explain why a client should not call refundDeposit.

Question 3 of 5

Use only this HarborCrane contract.

Member Kind Contract
loadKg attribute int mass currently on the hook
lift method sets loadKg to the given int
clear method sets loadKg to 0
readLoad method returns loadKg

(a) Identify the attribute and the methods. (b) After lift is used with 15, what does readLoad return? (c) A student wants the crane to rotate 90 degrees. Explain whether this API documents that behavior.

Question 4 of 5

A photographer reads DarkroomTimer documentation before writing a client.

Member Kind Contract
seconds attribute int remaining darkroom time
wind method sets seconds to the given int
tick method decreases seconds by 1 if seconds is positive
remaining method returns seconds

(a) Explain how comments or Javadoc in an API help without showing every method body. (b) After wind is used with 5, then tick is used once, what does remaining return? (c) Contrast an attribute with a method using seconds and tick.

Question 5 of 5

A teammate plans to call HarborCrane.dropAll() and TrailKiosk.printColorCopy() because those names seem convenient.

Member Kind Contract
loadKg attribute int mass currently on the hook
lift method sets loadKg to the given int
clear method sets loadKg to 0
readLoad method returns loadKg
Member Kind Contract
mapsLeft attribute int number of printed trail maps
dispense method decreases mapsLeft by 1 if mapsLeft is positive
restock method adds the given int to mapsLeft
countMaps method returns mapsLeft

(a) Check each planned name against the supplied contracts. (b) Choose documented members that actually empty the hook and that report the map count. (c) State a general rule about inventing methods that are not in the API.