Fiveable
💻AP Computer Science A
​

💻AP Computer Science A

FRQ 2 – Class Design
​
Unit 3: Class Creation
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 201/20

2. This question involves the StatusLabel class, which represents a label used to tag file names with a status. You will write the complete StatusLabel class, which contains a constructor and two methods.

StatusLabel objects are created by calls to a constructor with two parameters.

  • The first parameter is a String representing the status text (e.g., "Draft"). (Precondition: Assume that this value is a non-empty string.)

  • The second parameter is a boolean that indicates whether the status is urgent.

getFormattedTag

The StatusLabel class contains a getFormattedTag method, which returns a string representing the formatted status label based on the object's state.

  • The getFormattedTag method takes no parameters.

  • If the urgent parameter passed to the constructor was false, the returned string consists of the status text enclosed in square brackets (e.g., "[Draft]").

  • If the urgent parameter passed to the constructor was true, the returned string consists of the status text enclosed in square brackets with three asterisks on each side of the text (e.g., "[Draft]").

Returns the formatted status string.

processFileName

The StatusLabel class contains a processFileName method, which applies the status label to a given file name.

  • The method takes a single String parameter representing a file name.

  • The method first obtains the formatted tag by calling the getFormattedTag method.

  • If the file name parameter already contains the formatted tag, the method returns the file name unchanged.

  • If the file name ends with the extension ".txt", the method returns a new string with the formatted tag inserted immediately before the ".txt" extension.

  • In all other cases, the method returns a new string with the formatted tag appended to the end of the file name.

Returns the modified file name string containing the status label.

Statement

Return Value

Explanation

StatusLabel s1 = new StatusLabel("Draft", false);

s1 is created with status text "Draft" and is not urgent.

String t1 = s1.getFormattedTag();

"[Draft]"

Since s1 is not urgent, the tag is enclosed in simple brackets.

String f1 = s1.processFileName("essay.doc");

"essay.doc[Draft]"

The file name does not end in .txt and does not contain the tag, so the tag is appended to the end.

String f2 = s1.processFileName("notes.txt");

"notes[Draft].txt"

The file name ends in .txt, so the tag is inserted before the extension.

StatusLabel s2 = new StatusLabel("Secret", true);

s2 is created with status text "Secret" and is urgent.

String t2 = s2.getFormattedTag();

"[Secret]"

Since s2 is urgent, the tag is enclosed in brackets with asterisks.

String f3 = s2.processFileName("plan[Secret].pdf");

"plan[Secret].pdf"

The file name already contains the formatted tag, so the original string is returned.

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

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.