2025 AP Computer Science A FRQ #2

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. Intro: 00:00 Writing the class declaration: 01:40 Writing the constructor: 02:00 Writing the getSignature method: 04:18 Writing the addSignature method: 08:14 Final solution: 15:20