AP Computer Science A 2020 Practice Exam FRQ
AP Computer Science A 2020 Practice Exam FRQ
AP Computer Science A 2020 Practice Exam FRQ
You have 1 hour and 30 minutes to complete Section II. You may use
any blank space of the page the questions or documents are printed on
to organize your answers and for scratch work. You must write your
answers in the answer booklet for free-response questions. At the top
of each page in your booklet you must fill in the circle that indicates
the question number you are answering. Open your Section II booklet
and begin.
Note Start Time ________ . Note Stop Time ________ . After 1 hour and
20 minutes, say
There are 10 minutes remaining.
Collect a Section II booklet from each student and check that each student wrote
his or her answers on the pages corresponding to each question. Then say:
The exam is over. You are now dismissed.
Instructions
At a Glance
The questions for Section II are printed in this booklet. You may use the pages in this
Total Time booklet to organize your answers and for scratch work, but you must write your answers in
1 hour and 30 minutes the blank space provided for each question.
Number of Questions
4 The Java Quick Reference is located inside the front cover of this booklet.
Percent of Total Score
50%
Write your answer to each question in the blank space provided. Begin your response to
each question at the top of a new page and completely fill in the circle at the top of each
Writing Instrument
Pencil page that corresponds to the question you are answering.
Electronic Device All program segments must be written in Java. Show all your work. Credit for partial
None allowed solutions will be given. Write clearly and legibly. Erased or crossed-out work will not be
Weight scored.
The questions are
weighted equally. Manage your time carefully. Do not spend too much time on any one question. You may
proceed freely from one question to the next. You may review your responses if you finish
before the end of the exam is announced.
E remove(int index) Removes element from position index, moving elements at position
index + 1 and higher to the left (subtracts 1 from their indices) and
subtracts 1 from size; returns the element formerly at position index
Object Class
boolean equals(Object other)
String toString()
Directions: SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE
WRITTEN IN JAVA. You may plan your answers in this Questions booklet, but no credit will be given for anything
written in this booklet. You will only earn credit for what you write in the Free Response booklet.
Notes:
• Assume that the classes listed in the Java Quick Reference have been imported where appropriate.
• Unless otherwise noted in the question, assume that parameters in method calls are not null and that methods are
called only when their preconditions are satisfied.
• In writing solutions for each question, you may use any of the accessible methods that are listed in classes defined
in that question. Writing significant amounts of code that can be replaced by a call to one of these methods will not
receive full credit.
For this question, assume that when the rules are applied, the sequence will eventually terminate with the term
n = 1.
Example 1: 5, 16, 8, 4, 2, 1
• The first term is 5, so the second term is 5 * 3 + 1 =16.
16
• The second term is 16, so the third term is = 8.
2
8
• The third term is 8, so the fourth term is = 4.
2
4
• The fourth term is 4, so the fifth term is = 2.
2
2
• The fifth term is 2, so the sixth term is = 1.
2
• Since the sixth term is 1, the sequence terminates.
Example 2: 8, 4, 2, 1
8
• The first term is 8, so the second term is = 4.
2
4
• The second term is 4, so the third term is = 2.
2
2
• The third term is 2, so the fourth term is = 1.
2
• Since the fourth term is 1, the sequence terminates.
/** Returns true if the hailstone sequence that starts with n is considered long
* and false otherwise, as described in part (b).
* Precondition: n > 0
*/
public static boolean isLongSeq(int n)
{ /* to be implemented in part (b) */ }
/** Returns the proportion of the first n hailstone sequences that are considered long,
* as described in part (c).
* Precondition: n > 0
*/
public static double propLong(int n)
{ /* to be implemented in part (c) */ }
Write the method hailstoneLength(int n), which returns the length of the hailstone sequence
that starts with n.
/** Returns the length of a hailstone sequence that starts with n, as described in part (a).
* Precondition: n > 0
*/
public static int hailstoneLength(int n)
____________________________________________________________________
Begin your response at the top of a new page in the Free Response booklet
and fill in the appropriate circle indicating the question number.
If there are multiple parts to this question, write the part letter with your response.
Write the method isLongSeq(int n), which returns true if the hailstone sequence starting
with n is considered long and returns false otherwise. Assume that hailstoneLength
works as intended, regardless of what you wrote in part (a). You must use hailstoneLength
appropriately to receive full credit.
/** Returns true if the hailstone sequence that starts with n is considered long
* and false otherwise, as described in part (b).
* Precondition: n > 0
*/
public static boolean isLongSeq(int n)
____________________________________________________________________
Begin your response at the top of a new page in the Free Response booklet
and fill in the appropriate circle indicating the question number.
If there are multiple parts to this question, write the part letter with your response.
Consider the following table, which provides data about the hailstone sequences with starting values
between 1 and 10, inclusive.
The method call Hailstone.propLong(10) returns 0.5, since 5 of the 10 hailstone sequences
shown in the table are considered long.
Write the propLong method. Assume that hailstoneLength and isLongSeq work as
intended, regardless of what you wrote in parts (a) and (b). You must use isLongSeq appropriately to
receive full credit.
/** Returns the proportion of the first n hailstone sequences that are considered long,
* as described in part (c).
* Precondition: n > 0
*/
public static double propLong(int n)
____________________________________________________________________
Begin your response at the top of a new page in the Free Response booklet
and fill in the appropriate circle indicating the question number.
If there are multiple parts to this question, write the part letter with your response.
Value Returned
Statements (blank if no value Comment
returned)
GameSpinner g = new Creates a new spinner with four sectors
GameSpinner(4);
Returns the length of the current run. The length
g.currentRun(); 0 of the current run is initially 0 because no
spins have occurred.
Returns a random integer between 1 and 4,
g.spin(); 3 inclusive. In this case, 3 is returned.
The length of the current run is 1 because
g.currentRun(); 1 there has been one spin of 3 so far.
Returns a random integer between 1 and 4,
g.spin(); 3 inclusive. In this case, 3 is returned.
The length of the current run is 2 because
g.currentRun(); 2 there have been two 3s in a row.
Returns a random integer between 1 and 4,
g.spin(); 4 inclusive. In this case, 4 is returned.
The length of the current run is 1 because the
g.currentRun(); 1 spin of 4 is different from the value of the spin
in the previous run of two 3s.
Returns a random integer between 1 and 4,
g.spin(); 3 inclusive. In this case, 3 is returned.
The length of the current run is 1 because the
g.currentRun(); 1 spin of 3 is different from the value of the spin
in the previous run of one 4.
Returns a random integer between 1 and 4,
g.spin(); 1 inclusive. In this case, 1 is returned.
Returns a random integer between 1 and 4,
g.spin(); 1 inclusive. In this case, 1 is returned.
Returns a random integer between 1 and 4,
g.spin(); 1 inclusive. In this case, 1 is returned.
The length of the current run is 3 because
g.currentRun(); 3 there have been three consecutive 1s since the
previous run of one 3.
____________________________________________________________________
Begin your response at the top of a new page in the Free Response booklet
and fill in the appropriate circle indicating the question number.
If there are multiple parts to this question, write the part letter with your response.
The ReviewCollector class, shown below, is used to represent a collection of reviews to be analyzed.
public class ReviewCollector
{
private ArrayList<ProductReview> reviewList;
private ArrayList<String> productList;
/** Adds a new review to the collection of reviews, as described in part (a). */
public void addReview(ProductReview prodReview)
{ /* to be implemented in part (a) */ }
/** Returns the number of good reviews for a given product name, as described in part (b). */
public int getNumGoodReviews(String prodName)
{ /* to be implemented in part (b) */ }
____________________________________________________________________
Begin your response at the top of a new page in the Free Response booklet
and fill in the appropriate circle indicating the question number.
If there are multiple parts to this question, write the part letter with your response.
____________________________________________________________________
Begin your response at the top of a new page in the Free Response booklet
and fill in the appropriate circle indicating the question number.
If there are multiple parts to this question, write the part letter with your response.
public ReviewCollector()
public void addReview(ProductReview prodReview)
public int getNumGoodReviews(String prodName)
The Seat class, shown below, represents seats in the theater. The boolean instance variable
available is false if a ticket for the seat has been sold (the seat is no longer available). The int
instance variable tier indicates whether the seat is a tier 1 or tier 2 seat.
public class Seat
{
private boolean available;
private int tier;
/** Returns true if a seat holder was reassigned from the seat at fromRow, fromCol
* to the seat at toRow, toCol; otherwise it returns false, as described in part (b).
* Precondition: fromRow, fromCol, toRow, and toCol represent valid row and
* column positions in the theater.
* The seat at fromRow, fromCol is not available.
*/
public boolean reassignSeat(int fromRow, int fromCol,
int toRow, int toCol)
{ /* to be implemented in part (b) */ }
}
Row 0 of the theaterSeats array represents the row closest to the stage. All tier 1 seats are
closer to the stage than tier 2 seats.
____________________________________________________________________
Begin your response at the top of a new page in the Free Response booklet
and fill in the appropriate circle indicating the question number.
If there are multiple parts to this question, write the part letter with your response.
The reassignSeat method has four int parameters representing the row and column indexes of the
source (“from”) and destination (“to”) seats. If the reassignment is possible, the source seat becomes
available, the destination seat becomes unavailable, and the method returns true. If the seat
reassignment is not possible, no changes are made to either seat and the method returns false. Assume
that the source seat is occupied when the method is called.
____________________________________________________________________
Begin your response at the top of a new page in the Free Response booklet
and fill in the appropriate circle indicating the question number.
If there are multiple parts to this question, write the part letter with your response.
Page 2
Use a pencil only. Do NOT write your name. Do NOT write outside the box.
Q4854/2
AP Computer Science A Practice Exam 19
Important: Completely fill in the circle Question 1 Question 2 Question 3 Question 4
that corresponds to the question you
are answering on this page.
Page 3
Use a pencil only. Do NOT write your name. Do NOT write outside the box.
20 Q4854/3
AP Computer Science A Practice Exam
Important: Completely fill in the circle Question 1 Question 2 Question 3 Question 4
that corresponds to the question you
are answering on this page.
Page 4
Use a pencil only. Do NOT write your name. Do NOT write outside the box.
Q4854/4
AP Computer Science A Practice Exam 21
Important: Completely fill in the circle Question 1 Question 2 Question 3 Question 4
that corresponds to the question you
are answering on this page.
Page 5
Use a pencil only. Do NOT write your name. Do NOT write outside the box.
22 Q4854/5
AP Computer Science A Practice Exam
Important: Completely fill in the circle Question 1 Question 2 Question 3 Question 4
that corresponds to the question you
are answering on this page.
Page 6
Use a pencil only. Do NOT write your name. Do NOT write outside the box.
Q4854/6
AP Computer Science A Practice Exam 23
Important: Completely fill in the circle Question 1 Question 2 Question 3 Question 4
that corresponds to the question you
are answering on this page.
Page 7
Use a pencil only. Do NOT write your name. Do NOT write outside the box.
24 Q4854/7
AP Computer Science A Practice Exam
Important: Completely fill in the circle Question 1 Question 2 Question 3 Question 4
that corresponds to the question you
are answering on this page.
Page 8
Use a pencil only. Do NOT write your name. Do NOT write outside the box.
Q4854/8
AP Computer Science A Practice Exam 25
Important: Completely fill in the circle Question 1 Question 2 Question 3 Question 4
that corresponds to the question you
are answering on this page.
Page 9
Use a pencil only. Do NOT write your name. Do NOT write outside the box.
26 Q4854/9
AP Computer Science A Practice Exam
Important: Completely fill in the circle Question 1 Question 2 Question 3 Question 4
that corresponds to the question you
are answering on this page.
Page 10
Use a pencil only. Do NOT write your name. Do NOT write outside the box.
Q4854/10
AP Computer Science A Practice Exam 27
Important: Completely fill in the circle Question 1 Question 2 Question 3 Question 4
that corresponds to the question you
are answering on this page.
Page 11
Use a pencil only. Do NOT write your name. Do NOT write outside the box.
28 Q4854/11
AP Computer Science A Practice Exam
Important: Completely fill in the circle Question 1 Question 2 Question 3 Question 4
that corresponds to the question you
are answering on this page.
Page 12
Use a pencil only. Do NOT write your name. Do NOT write outside the box.
Q4854/12
AP Computer Science A Practice Exam 29