Verityprep
Question Bank

AP® Computer Science A Practice Questions

Work through AP Computer Science A practice 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.

Questions 3,111–3,120 of 3,140
  1. 3111
  2. 3112
  3. 3113
  4. 3114
  5. 3115
  6. 3116
  7. 3117
  8. 3118
  9. 3119
  10. 3120

Question 3111

Multiple choice Unit 4: Data Collections
Insertion sort is used on the array {9, 4, 7, 3, 8}. What is…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 3112

Multiple choice Unit 4: Data Collections
A binary search is performed on the sorted array {2, 5, 9, 14, 20, 27, 31, 40} for target 27. The midpoint is computed…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 3113

Multiple choice Unit 4: Data Collections
A text file "orders.txt" contains the following data. red 3 blue 5 green 2 Assume the file is opened successfully and the java.util.Scanner and java.io.File…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 3114

Multiple choice Unit 4: Data Collections
A text file "scores.txt" contains the following lines. Ava,7,true Bo,9,false Cy,10,true Assume the file is opened successfully and the java.util.Scanner and…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 3115

Multiple choice Unit 4: Data Collections

Consider the following recursive method.

public static int score(int[] arr, int k)
{
    if (k >= arr.length)
    {
        return 0;
    }

    int rest = score(arr, k + 2);

    if (arr[k] % 2 == 0)
    {
        return rest + arr[k];
    }
    return rest - arr[k];
}

What value is returned by the following code?

int[] values = {5, 2, 4, 7, 6};
score(values, 0);
Pick an answer, then check it. The solution opens in a window.

Question 3116

Free response Unit 4: Data Collections
The DeliveryWindow class stores the number of packages delivered during each recorded hour of a day. public class DeliveryWindow { private int[] packages;…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 3117

Free response Unit 4: Data Collections

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 3118

Free response Unit 4: Data Collections
An OrchardGrid object stores fruit counts for trees arranged in a rectangular grid. Each entry in fruit is the number of fruits currently on one tree. public…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 3119

Free response Unit 4: Data Collections
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 3120

Free response Unit 4: Data Collections
This question involves analyzing an orchard of apples to determine how many apple pies can be baked. The orchard is represented as a two-dimensional array of…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 3,111 of 3,140
Page 312 of 314