Verityprep
Question Bank · Unit 4

AP® Computer Science A Data Collections Practice Questions

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

Questions 1,191–1,200 of 1,222
  1. 1191
  2. 1192
  3. 1193
  4. 1194
  5. 1195
  6. 1196
  7. 1197
  8. 1198
  9. 1199
  10. 1200

Question 1191

Multiple choice Recursion
Consider the following recursive method. public static int recur(int n) { if (n < 3) {…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1192

Multiple choice Sorting And Searching
Selection sort is used on the array {6, 2, 8, 1,…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1193

Multiple choice Sorting And Searching
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 1194

Multiple choice Sorting And Searching
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 1195

Multiple choice Using Text Files
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 1196

Multiple choice Using Text Files
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 1197

Multiple choice Recursion

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 1198

Free response 2D Arrays
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 1199

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 1200

Free response 2D Arrays
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 1,191 of 1,222
Page 120 of 123