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 2Class Design3Tests class design, constructors, instance variables - all Unit 3 OOP content
FRQ 3Data Analysis with ArrayList4Tests using, analyzing, and manipulating data in an ArrayList - 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 the LogManager class, which is used to process and format log entries from a server. The LogManager class contains a helper method, getNextEntry. You will write two methods in the LogManager class.

</>Java
public class LogManager
{
    private String filterKeyword;

    /**
     * Initializes the LogManager with a filter keyword.
     */
    public LogManager(String keyword)
    {
        filterKeyword = keyword;
    }

    /**
     * Returns the next log entry to be processed, or null if no entries remain.
     * Postcondition: Returns a valid string or null.
     */
    public String getNextEntry()
    { /* implementation not shown */ }

    /**
     * Processes a single log entry based on the instance variable filterKeyword,
     * as described in part (a)
     * Precondition: entry is not null.
     */
    public String processEntry(String entry)
    { /* to be implemented in part (a) */ }

    /**
     * Generates a report containing processed versions of the next numEntries log entries,
     * as described in part (b)
     * Precondition: numEntries > 0
     */
    public String generateReport(int numEntries)
    { /* to be implemented in part (b) */ }

    /* There may be instance variables, constructors, and methods
       that are not shown. */
}
a.

Write the processEntry method, which formats a log entry based on the instance variable filterKeyword. If the entry contains the filterKeyword, the method should return the substring of the entry that appears after the first occurrence of the keyword. If the resulting substring is empty (meaning the keyword is at the end of the entry), the method should return "EMPTY". If the entry does not contain the filterKeyword, the method should return the original entry followed by " - NO MATCH".

Example 1

Assume the LogManager object was created with the keyword "ERROR". Consider the following calls to processEntry:
Method CallReturn Value
processEntry("System ERROR: Disk Full")": Disk Full"
processEntry("Critical ERROR")"EMPTY"
processEntry("User login successful")"User login successful - NO MATCH"
In the first call, "ERROR" is found, so the text after it (": Disk Full") is returned. In the second call, "ERROR" is at the end, so "EMPTY" is returned. In the third call, "ERROR" is not found, so " - NO MATCH" is appended.

Example 2

Assume the LogManager object was created with the keyword "WARN".
Method CallReturn Value
processEntry("Memory WARN low")" low"
processEntry("All systems nominal")"All systems nominal - NO MATCH"
Complete the processEntry method.
/**
 * Processes a single log entry based on the instance variable filterKeyword,
 * as described in part (a)
 * Precondition: entry is not null.
 */
public String processEntry(String entry)
b.

Write the generateReport method, which creates a single string containing the processed versions of the next numEntries log entries. The method should obtain each entry by calling the helper method getNextEntry. For each entry obtained, the method should call processEntry to format it and then append the result to the report followed by a newline character "
". If getNextEntry returns null before numEntries is reached, the method should stop processing and return the report generated so far.

You must use getNextEntry and processEntry appropriately to receive full credit.

Example

Assume filterKeyword is "ERROR". Suppose the next 3 calls to getNextEntry return "File ERROR missing", "Update complete", and "Disk ERROR", respectively.
Method CallReturn Value
generateReport(3)" missing Update complete - NO MATCH EMPTY\n"
The method processes 3 entries. "File ERROR missing" becomes " missing". "Update complete" becomes "Update complete - NO MATCH". "Disk ERROR" becomes "EMPTY". All are joined with newlines.
Complete the generateReport method.
/**
 * Generates a report containing processed versions of the next numEntries log entries,
 * as described in part (b)
 * Precondition: numEntries > 0
 */
public String generateReport(int numEntries)
Timed

00:00

Response auto-saves






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.