Fiveable
💻AP Computer Science A
​

💻AP Computer Science A

FRQ 3 – Data Analysis with ArrayList
​
Unit 4: Data Collections
​
AP CS A FRQ Types & Units

Each FRQ type tests specific skills taught in particular units. Here's why certain units appear for each question type:

FRQFocusUnitsWhy
FRQ 1Methods and Control Structures1-2Tests method writing, loops, conditionals - foundational programming from Units 1-2
FRQ 2Class Design3Tests class design, constructors, instance variables - all Unit 3 OOP content
FRQ 3Data Analysis with ArrayList4Tests using, analyzing, and manipulating data in an ArrayList - Unit 4 content
FRQ 42D Array4Tests 2D array traversal and manipulation - Unit 4 content

This mapping reflects College Board's exam structure - each FRQ type tests specific skills that are taught in particular units.

Practice FRQ 1 of 201/20

3. The Book class is used to store information about a book in a library. A partial declaration of the Book class is shown.

</>Java
public class Book
{
    /**
     * Returns the genre of the book
     */
    public String getGenre()
    { /* implementation not shown */ }

    /**
     * Returns the number of pages in the book
     */
    public int getPages()
    { /* implementation not shown */ }

    /**
     * Returns true if the book is currently available to be borrowed
     * and returns false otherwise
     */
    public boolean isAvailable()
    { /* implementation not shown */ }

    /* There may be instance variables, constructors, and
       methods that are not shown. */
}
</>Java
public class Library
{
    /** The list of all books in the library */
    private ArrayList<Book> collection;

    /**
     * Returns the average number of pages of the available books
     * in collection whose genre is equal to targetGenre
     * Precondition: targetGenre is not null
     *               At least one available element of
     *               collection has a genre equal to targetGenre.
     *               No elements of collection are null.
     */
    public double averagePagesForGenre(String targetGenre)
    { /* to be implemented */}

    /* There may be instance variables, constructors, and methods
       that are not shown. */
}

Write the Library method averagePagesForGenre. The method should return the average number of pages of the available books in collection that match the parameter targetGenre.

Suppose collection contains the following five Book objects.

Title

"The Hobbit"

"1984"

"The Alchemist"

"Harry Potter"

"Foundation"

Genre

"Fantasy"

"SciFi"

"Fantasy"

"Fantasy"

"SciFi"

Pages

300

320

200

405

250

Is Available

true

true

false

true

true

  • Call: averagePagesForGenre("Fantasy")

  • Return Value: 352.5

  • Explanation: which is equal to the average number of pages of the available books with the genre "Fantasy" (300 pages for "The Hobbit" and 405 pages for "Harry Potter"). "The Alchemist" is a "Fantasy" book but is not available, so it is not included in the calculation. (300 + 405) / 2.0 = 352.5.

Complete method averagePagesForGenre.

</>Java
/**
 * Returns the average number of pages of the available books
 * in collection whose genre is equal to targetGenre
 * Precondition: targetGenre is not null
 *               At least one available element of
 *               collection has a genre equal to targetGenre.
 *               No elements of collection are null.
 */
public double averagePagesForGenre(String targetGenre)
Timed

00:00

Response auto-saves






Pep

essential ap study content awaits..

Features
Testimonials
Testimonials
start studying →
FRQ Directions
Free Response Question Practice

This practice environment simulates the AP AP Computer Science A Free Response Questions section. Here are some guidelines:

  • Read each question carefully before responding. Pay attention to command verbs like "identify," "explain," "analyze," or "evaluate."
  • Use the timer to practice time management. You can pause, restart, or hide the timer as needed.
  • Mark for Review if you want to come back to a question later.
  • Your responses are saved automatically as you type. You can also use the drawing tool for questions that require diagrams or graphs.
  • Use the toolbar for formatting options like bold, italic, subscript, and superscript.
  • Navigate between questions using the Previous and Next buttons at the bottom of the screen.

Tip: Answer all parts of each question. Partial credit is often available, so even if you are unsure, provide what you know.