FRQ3 - ArrayLists - Part 1

From CS Awesome 2CC BY-NC-SA 4.0Original page

Java1 class period2 exercises4 graded tests

Files

README.mdDownload

FRQ3 - ArrayLists - Part 1

Each coding exercise has its own folder. Open its .java file and press Run to try it. Run Tests checks every graded exercise in this lesson at once.

From the 2025 Course and Exam Description:

Free-Response Question 3: Data Analysis with ArrayList. Students will be provided with a scenario and its associated class(es). Students will write one method of a given class based on provided specifications and examples. The method requires students to use, analyze, and manipulate data in an ArrayList structure.

FRQ 3 requires the following skills:

  • Iterate through an ArrayList
  • Access elements of an ArrayList
  • Call methods on elements of the ArrayList
  • Use a provided class

2007 FRQ3 - Student Answer Key - Part (a)

The following is a free response question from 2007. It was question 3 on the exam. You can see all the free response questions from past exams at Past AP CSA Exams.

Question 3. Consider a system for processing student test scores. The following class will be used as part of this system and contains a student’s name and the student’s answers for a multiple-choice test. The answers are represented as strings of length one with an omitted answer being represented by a string containing a single question mark ("?"). These answers are stored in an ArrayList in which the position of the answer corresponds to the question number on the test (question numbers start at 0). A student’s score on the test is computed by comparing the student’s answers with the corresponding answers in the answer key for the test. One point is awarded for each correct answer and 1/4 of a point is deducted for each incorrect answer. Omitted answers (indicated by "?") do not change the student’s score.

public class StudentAnswerSheet
{

    private List<String> answers;

    /** @param key the list of correct answers, represented as strings
     *         of length one
     *  Precondition: key.size() is equal to the number of answers in
     *         this answer sheet
     *  @return this student's test score
    public double getScore(List<String> key)
    {
      /* to be implemented in part (a) */
    }

    /** @return the name of the student
     */
    public String getName()
    {
       /* implementation not shown */
    }

    // There may be other fields, constructors, and methods

}

The following table shows an example of an answer key, a student’s answers, and the corresponding point values that would be awarded for the student’s answers. In this example, there are six correct answers, three incorrect answers, and one omitted answer. The student’s score is ((6 * 1) - (3 * 0.25)) = 5.25.

The answer key and student answers and point values

The answer key and student answers and point values

Part a. Write the StudentAnswerSheet method getScore. The parameter passed to method getScore is a List of strings representing the correct answer key for the test being scored. The method computes and returns a double that represents the score for the student’s test answers when compared with the answer key. One point is awarded for each correct answer and 1/4 of a point is deducted for each incorrect answer. Omitted answers (indicated by "?") do not change the student’s score.

The code below has a main method for testing the getScore method.

Exercise 1

Complete method getScore below.

Open the 01-StudentAnswerKeyA folder and edit StudentAnswerSheet.java. Press Run to try it; Run Tests checks it (2 tests).

2007 FRQ3 - Student Answer Key - Part (b)

Part b. Consider the following class that represents the test results of a group of students that took a multiple-choice test.

public class TestResults
{
    private List<StudentAnswerSheet> sheets;

    /**
     * Precondition: sheets.size() > 0; all answer sheets in sheets have the same
     * number of answers
     *
     * @param key the list of correct answers represented as strings of length one
     *     Precondition: key.size() is equal to the number of answers in each of
     *     the answer sheets in sheets
     * @return the name of the student with the highest score
     */
    public String highestScoringStudent(List<String> key)
    {
        /* to be implemented in part (b) */
    }

    // There may be fields, constructors, and methods that are not shown.
}

Write the TestResults method highestScoringStudent, which returns the name of the student who received the highest score on the test represented by the parameter key. If there is more than one student with the highest score, the name of any one of these highest-scoring students may be returned. You may assume that the size of each answer sheet represented in sheets is equal to the size of key.

Complete method highestScoringStudent below.

The code below has a main method for testing the highestScoringStudent method.

Exercise 2

Complete method highestScoringStudent below.

Open the 02-StudentAnswerKeyB folder and edit TestResults.java. Press Run to try it; Run Tests checks it (2 tests).

For teachers

FRQ3 - ArrayLists - Part 1

Students read CSAwesome2's “FRQ3 - ArrayLists - Part 1” in CS Room and work through its 2 Java coding exercises.

  • Time: 1 class period
  • Tests: 4 in 2 graded exercises, set up for you when you import the lesson

Goals

  • Practice for the AP exam's free-response questions.

Before class

In class

  1. Students read README.md.
  2. Students do exercises 01–02, each in its own folder, pressing Run to try their code.
  3. Run Tests checks every graded exercise at once; scores appear in the Gradebook. Grading uses your copy of the tests, so a student who edits theirs does not change the grade.

Exercises

FolderFileGradingTests
01-StudentAnswerKeyAStudentAnswerSheet.javaAutograded2
02-StudentAnswerKeyBTestResults.javaAutograded2

Teachers can download a reference solution after signing in.