AP® Computer Science A FRQ Practice: Free-Response Questions with Solutions
Work through AP Computer Science A free-response questions unit by unit, then check each answer against a worked solution.
Free · no sign-up Open questions need no account. Sign up or log in to open the rest.
Question 302
Information about applicants for a scholarship program is stored in Applicant objects.
public class Applicant
{
private String name;
private int score;
private boolean complete;
public Applicant(String n, int s, boolean c)
{
name = n;
score = s;
complete = c;
}
public String getName()
{
return name;
}
public int getScore()
{
return score;
}
public boolean isComplete()
{
return complete;
}
}
The ScholarshipGroup class stores a list of applicants.
public class ScholarshipGroup
{
private ArrayList<Applicant> applicants;
public ScholarshipGroup(ArrayList<Applicant> list)
{
applicants = list;
}
public ArrayList<String> finalists(int minScore)
{ /* to be written */ }
}
Write the method finalists, which returns a new ArrayList<String> containing the names of all applicants who satisfy both of the following conditions.
- The applicant's form is complete.
- The applicant's score is at least
minScore.
Among the applicants who satisfy those conditions, only applicants whose score is equal to the highest qualifying score should appear in the returned list. Names in the returned list must appear in the same order as the corresponding applicants appear in applicants. If no applicant qualifies, the method returns an empty list.
For example, if the qualifying applicants have scores 81, 94, 94, 88, the returned list should contain the names of the two applicants whose score is 94, in their original order.
Answer images
Question 303
Question 304
Question 305
Question 306
A school system models course requests using the CourseRequest class. A request has a course name, a priority value, and a flag indicating whether the request has already been fulfilled.
public class CourseRequest
{
private String courseName;
private int priority;
private boolean fulfilled;
public CourseRequest(String name, int p, boolean done)
{
courseName = name;
priority = p;
fulfilled = done;
}
public String getCourseName()
{
return courseName;
}
public int getPriority()
{
return priority;
}
public boolean isFulfilled()
{
return fulfilled;
}
}
public class CourseQueue
{
private ArrayList<CourseRequest> requests;
public CourseQueue(ArrayList<CourseRequest> data)
{
requests = data;
}
public ArrayList<String> topOpenRequests(int minPriority)
{ /* to be written */ }
}
Write the method topOpenRequests, which returns a new ArrayList<String> containing the names of all unfulfilled requests whose priority is at least minPriority and is equal to the highest priority among all such requests. Names must appear in the same order as the corresponding requests appear in requests. If no request qualifies, the method returns an empty list.
Main Solution
Sample Solution
public ArrayList<String> topOpenRequests(int minPriority)
{
ArrayList<String> result = new ArrayList<String>();
int best = 0;
boolean found = false;
for (int i = 0; i < requests.size(); i++)
{
CourseRequest req = requests.get(i);
if (!req.isFulfilled() && req.getPriority() >= minPriority)
{
if (!found || req.getPriority() > best)
{
best = req.getPriority();
found = true;
}
}
}
if (!found)
{
return result;
}
for (int i = 0; i < requests.size(); i++)
{
CourseRequest req = requests.get(i);
if (!req.isFulfilled() && req.getPriority() == best)
{
result.add(req.getCourseName());
}
}
return result;
}
Scoring (9 pts): Points are earned for creating a result list, traversing all requests, using accessor methods, filtering by unfulfilled status and minimum priority, finding the best qualifying priority, handling no qualifying requests, collecting all ties in original order, adding course names rather than request objects, and returning the result.
Answer images
Question 307
Question 308
Question 309
Question 310
AP® and Advanced Placement® are registered trademarks of the College Board, which is not affiliated with, and does not endorse, Verityprep. Names are used for identification purposes only.

