Fiveable
💻AP Computer Science A
​

💻AP Computer Science A

FRQ 1 – Methods and Control Structures
​
Unit 1: Using Objects and Methods
​
AP CS A FRQ Types & Units

Each FRQ type tests specific skills taught in particular units. Here's why certain units appear for each question type:

FRQFocusUnitsWhy
FRQ 1Methods and Control Structures1-2Tests method writing, loops, conditionals - foundational programming from Units 1-2
FRQ 2Classes3Tests class design, constructors, instance variables - all Unit 3 OOP content
FRQ 3Array/ArrayList4Tests 1D array and ArrayList traversal, manipulation - Unit 4 content
FRQ 42D Array4Tests 2D array traversal and manipulation - Unit 4 content

This mapping reflects College Board's exam structure - each FRQ type tests specific skills that are taught in particular units.

Practice FRQ 1 of 191/19
1. This question involves a security system that controls access to a secure facility. The system tracks failed attempts and can lock out users. You will write two methods for the SecuritySystem class.
</>Java
public class SecuritySystem
{
    private int failedAttempts; // Tracks consecutive failed attempts
    private boolean isLocked;   // true if the system is locked out

    /**
     * Simulates a biometric scan (e.g., fingerprint or retina).
     * Returns true if the scan is verified, false otherwise.
     */
    public boolean checkBiometric()
    { /* implementation not shown */ }

    /**
     * Processes an access attempt using the provided code.
     * Updates the system state and returns true if access is granted,
     * false otherwise, as described in part (a).
     */
    public boolean attemptAccess(String code)
    { /* to be implemented in part (a) */ }

    /**
     * Processes a stream of codes separated by spaces.
     * Calls attemptAccess for each code and returns the total number
     * of successful accesses, as described in part (b).
     * Precondition: codeStream contains at least one code and ends with a space.
     */
    public int processLog(String codeStream)
    { /* to be implemented in part (b) */ }

    /* There may be instance variables, constructors, and methods
       that are not shown. */
}
a. Write the attemptAccess method, which processes a request to enter the facility. The method accepts a code as a parameter and proceeds according to the following rules:
1. If the system is already locked (isLocked is true), the method returns false immediately without checking the code or biometrics.
2. If the code is equal to "ADMIN_RESET", the system resets: failedAttempts is set to 0, isLocked is set to false, and the method returns true.
3. If the code is not "ADMIN_RESET", the method calls the helper method checkBiometric.
- If checkBiometric returns true, failedAttempts is reset to 0 and the method returns true.
- If checkBiometric returns false, failedAttempts is incremented by 1. If failedAttempts then reaches 3 or more, isLocked is set to true. The method returns false.
You must use the checkBiometric helper method. Do not implement checkBiometric.

Example 1

Assume the system starts with failedAttempts = 0 and isLocked = false.
Method CallcheckBiometric() ReturnsReturn ValueSystem State After Call
attemptAccess("1234")falsefalsefailedAttempts = 1, isLocked = false
attemptAccess("5678")falsefalsefailedAttempts = 2, isLocked = false
attemptAccess("9999")truetruefailedAttempts = 0, isLocked = false
In the third call, the biometric check passed, so the failure count was reset.

Example 2

Assume the system starts with failedAttempts = 2 and isLocked = false.
Method CallcheckBiometric() ReturnsReturn ValueSystem State After Call
attemptAccess("0000")falsefalsefailedAttempts = 3, isLocked = true
attemptAccess("1111")(not called)falsefailedAttempts = 3, isLocked = true
attemptAccess("ADMIN_RESET")(not called)truefailedAttempts = 0, isLocked = false
The first call caused the system to lock. The second call failed immediately because of the lock. The third call used the admin code to unlock the system.
Complete the attemptAccess method.
/**
 * Processes an access attempt using the provided code.
 * Updates the system state and returns true if access is granted,
 * false otherwise, as described in part (a).
 */
public boolean attemptAccess(String code)
b. Write the processLog method, which processes a string of codes representing a sequence of access attempts. The parameter codeStream contains multiple codes, each separated by a single space. The string is guaranteed to end with a space.
The method should extract each code from codeStream, call attemptAccess with that code, and count how many times attemptAccess returns true. Finally, the method should return the total count of successful accesses.
You must call attemptAccess in your solution.

Example 1

Assume checkBiometric() always returns false for regular codes.
Method CallReturn Value
processLog("1111 2222 ADMIN_RESET 3333 ")1
Processing: "1111" (fails), "2222" (fails), "ADMIN_RESET" (succeeds, unlocks), "3333" (fails). Total successes: 1.

Example 2

Assume checkBiometric() always returns true.
Method CallReturn Value
processLog("A1 B2 C3 ")3
All three codes result in a successful access. Total successes: 3.
Complete the processLog method.
/**
 * Processes a stream of codes separated by spaces.
 * Calls attemptAccess for each code and returns the total number
 * of successful accesses, as described in part (b).
 * Precondition: codeStream contains at least one code and ends with a space.
 */
public int processLog(String codeStream)






Pep

essential ap study content awaits..

Features
Testimonials
Testimonials
start studying →
FRQ Directions
Free Response Question Practice

This practice environment simulates the AP AP Computer Science A Free Response Questions section. Here are some guidelines:

  • Read each question carefully before responding. Pay attention to command verbs like "identify," "explain," "analyze," or "evaluate."
  • Use the timer to practice time management. You can pause, restart, or hide the timer as needed.
  • Mark for Review if you want to come back to a question later.
  • Your responses are saved automatically as you type. You can also use the drawing tool for questions that require diagrams or graphs.
  • Use the toolbar for formatting options like bold, italic, subscript, and superscript.
  • Navigate between questions using the Previous and Next buttons at the bottom of the screen.

Tip: Answer all parts of each question. Partial credit is often available, so even if you are unsure, provide what you know.