2025 AP Computer Science A FRQ #1A

In part A, you will write the Account constructor, which creates a username based on the parameter requestedName. A helper method, isAvailable, has been provided to determine whether a username is available. The isAvailable method returns true if its parameter is an available username and returns false otherwise. If requestedName is an available username, the Account constructor will assign requestedName to the instance variable username. If not, the constructor will try different variations of requestedName until an available username is found and assigned to the instance variable username. The variations consist of requestedName followed by an integer, as in the following example. • If requestedName is "Luis-Cruz" and this username is not available, then the constructor will check the availability of "Luis-Cruz1", "Luis-Cruz2", "LuisCruz3", and so on, until an available username is found. The first available username found is assigned to username. • If requestedName is "PSmith" and this username is available, then "PSmith" is assigned to username. Complete the Account constructor. You must use isAvailable appropriately in order to receive full credit. Intro: 00:00 Pseudocode: 01:39 Writing the code: 02:55 Testing the code: 07:22 Final solution: 10:08