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 managing student enrollment for a computer science course using the CourseEnrollment class. The CourseEnrollment class maintains a roster of enrolled students and tracks the number of seats remaining. A helper method, checkPrereq, is provided to determine if a student meets the prerequisites for the course.
</>Java
public class CourseEnrollment
{
    /** The number of seats currently available in the course */
    private int seatsRemaining;

    /** The list of enrolled students, names separated by a single space */
    private String roster; // Initialized to "" in the constructor

    /**
     * Initializes the course with a specified number of seats and an empty roster.
     * Precondition: seats > 0
     */
    public CourseEnrollment(int seats)
    { /* implementation not shown */ }

    /**
     * Returns true if the student with the given name meets the
     * prerequisites for the course, false otherwise.
     * Precondition: name is not null
     */
    public boolean checkPrereq(String name)
    { /* implementation not shown */ }

    /**
     * Enrolls a student if there are seats available and the student
     * meets the prerequisites, as described in part (a).
     * Precondition: name is not null
     */
    public boolean enrollStudent(String name)
    { /* to be implemented in part (a) */ }

    /**
     * Processes a string of names from a waitlist and attempts to enroll
     * each student, as described in part (b).
     * Precondition: names ends with a space.
     */
    public int processWaitList(String names)
    { /* to be implemented in part (b) */ }

    /* There may be instance variables, constructors, and methods
       that are not shown. */
}
a. Write the enrollStudent method, which attempts to enroll a student with the given name. The method should verify that seatsRemaining is greater than 0 and that the student meets the prerequisites by calling the checkPrereq method.
If both conditions are met, the method should:
1. Decrease seatsRemaining by 1.
2. Append the name followed by a space to the instance variable roster.
3. Return true.
Otherwise, the method should return false and make no changes to the instance variables.
You must use the checkPrereq method to determine eligibility. The roster string stores names separated by a single space.

Example 1

Assume a CourseEnrollment object has been created with 2 seats remaining and an empty roster. Consider the following calls to enrollStudent.
Method CallcheckPrereq(name)seatsRemaining (before)Return ValueseatsRemaining (after)
enrollStudent("Alex")true2true1
enrollStudent("Sam")false1false1
enrollStudent("Jordan")true1true0
enrollStudent("Casey")true0false0
After these calls, the instance variable roster would contain "Alex Jordan ".
Complete the enrollStudent method.
/**
 * Enrolls a student if there are seats available and the student
 * meets the prerequisites, as described in part (a).
 * Precondition: name is not null
 */
public boolean enrollStudent(String name)
b. Write the processWaitList method, which attempts to enroll students from a string of names. The parameter names contains student names separated by a single space. The string is guaranteed to end with a space.
The method should:
1. Traverse the names string to extract each individual student name.
2. Call enrollStudent for each name extracted.
3. Return the total number of students successfully enrolled.

Example 1

Assume a CourseEnrollment object has 2 seats remaining. Also assume checkPrereq returns true for "Alex" and "Jordan", but false for "Sam".
Method CallReturn Value
processWaitList("Alex Sam Jordan ")2
The method processes "Alex" (enrolled), then "Sam" (not enrolled due to prereq), then "Jordan" (enrolled). The method returns 2.
Complete the processWaitList method. You must use enrollStudent appropriately in order to receive full credit.
/**
 * Processes a string of names from a waitlist and attempts to enroll
 * each student, as described in part (b).
 * Precondition: names ends with a space.
 */
public int processWaitList(String names)






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 carefullybefore 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.