AP Computer Science A FRQ Practice


1. Array Manipulation

Question:

Consider the following method:

public static int[] processArray(int[] arr) {
    int[] result = new int[arr.length];
    for (int i = 0; i < arr.length; i++) {
        result[i] = arr[i] * 2;
    }
    return result;
}

(a) What will be the output of the method if the input array is {1, 2, 3, 4, 5}?

(b) Modify the method to create a new array where each element is the square of the corresponding element in the original array.

Response Guidelines:

  • Part (a):
    The method multiplies each element in the array by 2. Apply this transformation to each element of the input array {1, 2, 3, 4, 5}.
  • Part (b):
    Modify the method so that the new array contains the square of each element from the original array. This requires changing the multiplication inside the loop.

2. Inheritance and Polymorphism

Question:

Consider the following class hierarchy:

public class Animal {
    public void makeSound() {
        System.out.println("Animal makes sound");
    }
}

public class Dog extends Animal {
    public void makeSound() {
        System.out.println("Woof");
    }
}

public class Cat extends Animal {
    public void makeSound() {
        System.out.println("Meow");
    }
}

(a) What will the following code output?

Animal animal = new Dog();
animal.makeSound();
animal = new Cat();
animal.makeSound();

(b) Explain the concept that allows the code to output different results for each makeSound() method call.

Response Guidelines:

  • Part (a):
    The code creates an Animal reference pointing to a Dog object, which calls the makeSound() method from the Dog class. Then, the reference is reassigned to a Cat object, which calls the makeSound() method from the Cat class.
  • Part (b):
    The concept demonstrated is polymorphism, where the method that is called depends on the type of the object the reference is pointing to, not the type of the reference itself.

3. Looping and Conditional Statements

Question:

Write a method that accepts a list of integers and returns the count of integers that are divisible by 3 but not divisible by 5.

public static int countDivisibleBy3Not5(List<Integer> list) {
    // Implement your code here
}

Response Guidelines:

  • Loop through the list of integers.
  • For each integer, check if it is divisible by 3 but not divisible by 5.
  • Increment the count for each integer that satisfies the condition.

Grading Rubric for AP Computer Science A FRQs


1. Array Manipulation

  • Part (a):
    • 0-1 points: Incorrect output or no output.
    • 2 points: Correct output of the array, showing proper multiplication of each element by 2.
  • Part (b):
    • 0-1 points: Code does not correctly modify the array to contain the squares of the elements.
    • 2 points: Code correctly modifies the array to contain the squares of the elements.

2. Inheritance and Polymorphism

  • Part (a):
    • 0-1 points: Incorrect output or misunderstanding of polymorphism.
    • 2 points: Correctly identifies that the output will be "Woof" followed by "Meow."
  • Part (b):
    • 0-1 points: Does not correctly explain polymorphism or provides an incorrect explanation.
    • 2 points: Correctly explains the concept of polymorphism and how the method call is determined by the object's actual type.

3. Looping and Conditional Statements

  • Part (a):
    • 0-1 points: Incorrect or incomplete code.
    • 2 points: Correctly implements the loop and condition to count integers divisible by 3 but not by 5.

Sample Grading Breakdown (for one FRQ)

  • Array Manipulation: 4 points
  • Inheritance and Polymorphism: 4 points
  • Looping and Conditional Statements: 4 points
  • Total: 12 points (for all three FRQs combined)