AP CSA FRQ Guide

2023 FRQ 2: Sign

Write a complete Sign class that stores a message and line width. The class reports how many lines are needed and returns the message split into width-sized chunks separated by semicolons, with the empty-message case handled correctly.

Complete Class and String Formatting22 minute targetclass writingconstructorsString methodssubstringedge cases

Skills Tested

What this FRQ is really practicing

class writingconstructorsString methodssubstringedge cases

Treat these skills as the study checklist. If any tag feels shaky, review that topic before attempting the full written response.

Starter Approach

How to begin without copying a solution

  1. 1Write the complete class header, private instance variables, and constructor.
  2. 2Implement numberOfLines using the stored message length and line width, including the empty-message case.
  3. 3Implement getLines by splitting the message into line-width chunks separated by semicolons.
  4. 4Return null from getLines when the stored message is empty.

Write a first attempt before revealing any solution outline. Most AP CSA FRQ progress comes from tracing your own code and finding the missing case.

Common Mistakes

Mistakes to watch for while writing

Using integer division directly and missing the final partial line.
Returning an empty string instead of null from getLines for the empty-message case.
Adding a semicolon after the last line.
Splitting only on spaces instead of splitting by the fixed line width.
Changing the stored message during getLines, causing repeated calls to behave differently.

Self Check

Review questions before you submit

Uses the correct public class header.

Question 2 asks for the complete Sign class.

Declares fields to store the message and width.

The constructor values need to be available to both methods.

Includes a Sign constructor with String and int parameters.

The constructor name must match the class name exactly.

Stores constructor parameters in instance variables.

Assign both the message and width parameters to fields.

Defines numberOfLines with int return type and no parameters.

This method returns the number of display lines needed.

Handles the empty-message case in numberOfLines.

An empty message needs zero lines.

Uses ceiling-style division for the line count.

A remainder means one additional line is needed.

Defines getLines with String return type and no parameters.

This method returns a formatted String or null.

Practice Links

Where to go next