Skip to main content
Logo image

Section 15.8 FRQ 2 - Class Design - Part 2

From the 2025 Course and Exam Description:
Free-Response Question 2: Class Design. Students will be instructed to design and implement a class based on provided specifications and examples. A second class might also be included. Students will be provided with a scenario and specifications in the form of a table demonstrating ways to interact with the class and the results. The class must include a class header, instance variables, a constructor, a method, and implementation of the constructor and required method.
FRQ 2 requires the following skills:
  • Create a class header
  • Determine what private instance variables are needed by the class
  • Write a constructor with appropriate parameters
  • Implement a method according to the behavior specified in the table
Teacher Insights
  • You do not need to include import statements. You can assume that any standard Java class is already imported.
  • You will NEVER print. If you think you need to print, you probably need to return something.
  • You will NOT need to write a main. In this question, they are giving you the main.

Subsection 15.8.1 2025 FRQ2 - Signed Text

This question involves the SignedText class, which contains methods that are used to include a signature as part of a string of text. You will write the complete SignedText class, which contains a constructor and two methods.
The SignedText constructor takes two String parameters. The first parameter is a first name and the second parameter is a last name. The length of the second parameter is always greater than or equal to 1.
The getSignature method takes no parameters and returns a formatted signature string constructed from the first and last names according to the following rules.
  • If the first name is an empty string, the returned signature string contains just the last name.
  • If the first name is not an empty string, the returned signature string is the first letter of the first name, a dash ("-"), and the last name, in that order.
The addSignature method returns a possibly revised copy of its String parameter. The parameter will contain at most one occurrence of the object’s signature, at either the beginning or the end of the parameter. The returned string is created from the parameter according to the following rules.
  • If the object’s signature does not occur in the String parameter of the method, the returned String is the value of the parameter with the signature added to the end.
  • If the object’s signature occurs at the end of the String parameter, the returned String is the unchanged value of the parameter.
  • If the object’s signature occurs at the beginning of the String parameter, the returned String is the value of the original parameter with the signature removed from the beginning and appended to the end of the parameter.
The following table contains a sample code execution sequence and the corresponding results. The code execution sequence appears in a class other than SignedText.
Figure 15.8.1. Part 1 of SignedText Table
Figure 15.8.2. Part 2 of SignedText Table

Activity 15.8.1.

Write the complete SignedText class. Your implementation must meet all specifications and conform to the examples in the table.

Subsection 15.8.2 2023 FRQ 2 - Sign

This question involves methods that distribute text across lines of an electronic sign. The electronic sign and the text to be displayed on it are represented by the Sign class. You will write the complete Sign class, which contains a constructor and two methods.
The Sign class constructor has two parameters. The first parameter is a String that contains the message to be displayed on the sign. The second parameter is an int that contains the width of each line of the sign. The width is the positive maximum number of characters that can be displayed on a single line of the sign.
A sign contains as many lines as are necessary to display the entire message. The message is split among the lines of the sign without regard to spaces or punctuation. Only the last line of the sign may contain fewer characters than the width indicated by the constructor parameter.
The following are examples of a message displayed on signs of different widths. Assume that in each example, the sign is declared with the width specified in the first column of the table and with the message "Everything on sale, please come in", which contains 34 characters.
The following table contains a sample code execution sequence and the corresponding results. The code execution sequence appears in a class other than Sign.
Figure 15.8.3.

Activity 15.8.2.

Write the complete Sign class. Your implementation must meet all specifications and conform to the examples shown in the preceding table.
You have attempted of activities on this page.