Verityprep
Question Bank · Unit 4

AP® Computer Science A Data Collections FRQ

Work through AP Computer Science A free-response questions on Data Collections, 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.

Subtopic: Arraylists Clear filter

Questions 51–52 of 52
  1. 51
  2. 52

Question 51

Free response Arraylists

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.

The answer and the full solution open in a window.

Question 52

Free response Arraylists
This question involves the analysis of messages exchanged in a chat room. The following Message class represents a single message in the chat room. public class…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 51 of 52
Page 6 of 6