2025 AP CSA FRQ 2 - Signedtext
2025 AP CSA FRQ 2: SignedText
Class Writing
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.
Provided Code
Part FULL: Complete Class (9 points)
9 pointspublic 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 |
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
// Wrong:
verified = true; // WRONG
// Correct:
verified = false; // Initially unverified// Wrong:
return text + " [UNVERIFIED " + signature + "]"; // Missing colon
// Correct:
return text + " [UNVERIFIED: " + signature + "]";// Wrong:
return text + "[" + signature + "]"; // Missing space
// Correct:
return text + " [" + signature + "]";// Wrong:
public boolean verify() { verified = true; return true; }
// Correct:
public void verify() { verified = true; }// Wrong:
if (verified == true)
// Correct:
if (verified) // CleanerExam 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
Related FRQs
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.
Message Sent!
Thanks for reaching out. I'll get back to you within 24 hours.
tanner@apcsexamprep.com
Courses
AP CSA, CSP, & Cybersecurity
Response Time
Within 24 hours
Prefer email? Reach me directly at tanner@apcsexamprep.com