2025 AP CSA FRQ 2 - Signedtext

2025 AP CSA FRQ 2: SignedText

Class Writing

Class Writing 9 Points Total Medium
Practice Timer (22 min recommended) 22:00

Overview: The SignedText class represents text that has been digitally signed. It stores the original text, the signature (author's name), and whether the signature is verified. The class provides methods to get the signed text in various formats and to verify the signature.

Topics Covered: Class DesignInstance VariablesConstructorsString ManipulationBoolean Logic

Provided Code

Part FULL: Complete Class (9 points)

9 points
Write the complete SignedText class. Your class must include: - A constructor that takes the text and signature as parameters. The text is initially unverified. - A getText method that returns the original text. - A getSignature method that returns the signature (author name). - An isVerified method that returns whether the text has been verified. - A verify method that marks the text as verified. - A getSignedText method that returns the text with signature appended: - If verified: "text [signature]" - If not verified: "text [UNVERIFIED: signature]"
Method Signature: public class SignedText

Examples

SignedText msg = new SignedText("Hello World", "Alice");

Call Returns Explanation
msg.getText() "Hello World" Returns the original text
msg.getSignature() "Alice" Returns the signature
msg.isVerified() false Initially unverified
msg.getSignedText() "Hello World [UNVERIFIED: Alice]" Shows unverified format
msg.verify(); msg.isVerified() true Now verified
msg.getSignedText() "Hello World [Alice]" Shows verified format
View Solution and Rubric

Scoring Rubric

+1 Declares private instance variable for text
+1 Declares private instance variable for signature
+1 Declares private instance variable for verified status (boolean)
+1 Constructor initializes all instance variables (verified starts false)
+1 getText returns the text
+1 getSignature returns the signature
+1 isVerified returns the verified status
+1 verify sets verified to true
+1 getSignedText returns correctly formatted string based on verified status

Solution

public class SignedText
{
    private String text;
    private String signature;
    private boolean verified;
    
    public SignedText(String t, String sig)
    {
        text = t;
        signature = sig;
        verified = false;
    }
    
    public String getText()
    {
        return text;
    }
    
    public String getSignature()
    {
        return signature;
    }
    
    public boolean isVerified()
    {
        return verified;
    }
    
    public void verify()
    {
        verified = true;
    }
    
    public String getSignedText()
    {
        if (verified)
        {
            return text + " [" + signature + "]";
        }
        else
        {
            return text + " [UNVERIFIED: " + signature + "]";
        }
    }
}

Step-by-Step Explanation

Step 1: Declare three private instance variables: text (String), signature (String), and verified (boolean).

Step 2: Constructor takes text and signature parameters, initializes both, and sets verified to false.

Step 3: getText(), getSignature(), and isVerified() are simple accessor methods.

Step 4: verify() is a mutator that sets verified to true.

Step 5: getSignedText() builds a string based on the verified status, using the correct format for each case.

Using ternary operator in getSignedText

public String getSignedText()
{
    String prefix = verified ? "" : "UNVERIFIED: ";
    return text + " [" + prefix + signature + "]";
}

Common Mistakes to Avoid

Initializing verified to true instead of false
Text should start as unverified per the problem description.
// Wrong:
verified = true;  // WRONG

// Correct:
verified = false;  // Initially unverified
Wrong format for unverified text
Must exactly match: "text [UNVERIFIED: signature]" with colon and space.
// Wrong:
return text + " [UNVERIFIED " + signature + "]";  // Missing colon

// Correct:
return text + " [UNVERIFIED: " + signature + "]";
Forgetting the space before the bracket
Format requires a space between text and bracket.
// Wrong:
return text + "[" + signature + "]";  // Missing space

// Correct:
return text + " [" + signature + "]";
Making verify() return something
verify() should be void - it just modifies state.
// Wrong:
public boolean verify() { verified = true; return true; }

// Correct:
public void verify() { verified = true; }
Using == instead of boolean variable directly
For booleans, just use the variable directly in conditions.
// Wrong:
if (verified == true)

// Correct:
if (verified)  // Cleaner

Exam Tips

  • Copy the exact format from the examples - every space, bracket, and colon matters
  • Boolean variables don't need explicit initialization to false, but showing it demonstrates understanding
  • Accessor methods are simple returns; don't overcomplicate them
  • void methods don't return anything - verify() just sets the flag
  • String concatenation with + works fine for building the result

Official College Board Resources

Original Question PDF Scoring Guidelines

Get in Touch

Whether you're a student, parent, or teacher — I'd love to hear from you.

Just want free AP CS resources?

Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

tanner@apcsexamprep.com

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at tanner@apcsexamprep.com