Home Quizzes Quiz Detail
Practice Quiz

AP CSP Practice Test - Unit 6 Array, Unit 7 ArrayList and Unit 8 2D Array

36 questions 5.0 rating Mobile friendly
$69.00

Unlock the full practice quiz

Get complete access to the questions, explanations and printable quiz resources.

Full access: unlock all quiz questions and explanations.
Printable review: access the full quiz PDF with correct answers after purchase.

About this Exam

Prepare with the AP CSP Practice Test - Unit 6 Array, Unit 7 ArrayList and Unit 8 2D Array practice quiz. This question bank includes 36 questions covering public, string, return, private, and double. Use it to review important concepts, identify knowledge gaps, and build confidence for the related exam, course, or assessment.

Sample Questions

Question 1
Questions refer to the Ticket and Transaction classes below public class Ticket { private String row; private int seat; private double price; //constructor public Ticket(String aRow, int aSeat, double aPrice) { row = aRow; seat = aSeat; price = aPrice; } //accessors getRow(), getSeat(), and getPrice() ... } public class Transaction { private int numTickets; private Ticket[] tickList; //constructor public Transaction(int numTicks) { numTickets = numTicks; tickList = new Ticket[numTicks]; String theRow; int theSeat; double thePrice; for (int i = 0; i < numTicks; i++) { < read user input for theRow, theSeat, and thePrice > ... /* more code */ } } /** @return total amount paid for this transaction */ public double totalPaid() { double total = 0.0; /* code to calculate amount */ return total; } } Which represents correct /* code to calculate amount */ in the totalPaid method?
An array of primitive number types is more efficient to manipulate than an ArrayList of wrapper objects that contain numbers.
for (Coin c : coins) { total += c.getValue(); }
for (Ticket t : tickList) total += t.getPrice();
Reflects mat through its minor diagonal. For example
Explanation:
Correct answer: for (Ticket t : tickList) total += t.getPrice();
Question 2
Refer to the following code segment. You may assume that array arr1 contains elements arr1[0], arr1[1], . . . , arr1[N-1] , where N = arr1.length . int count = 0; for (int i = 0; i < N; i++) { if (arr1[i] != 0) { arr1[count] = arr1[i]; count++; } } int[] arr2 = new int[count]; for (int i = 0; i < count; i++) { arr2[i] = arr1[i]; } If array arr1 initially contains the elements 0, 6, 0, 4, 0, 0, 2 in this order, what will arr2 contain after execution of the code segment?
6, 4, 2
1 3
k - 1
strList.add(intOb + 8);
Explanation:
Correct answer: 6, 4, 2
Question 3
Consider this class: public class BingoCard { private int[] card; /** Default constructor: Creates BingoCard with * 20 random digits in the range 1 - 90. */ public BingoCard() { /* implementation not shown */ } /* Display BingoCard. */ public void display() { /* implementation not shown */ } ... } Assuming that players has been declared as an array of BingoCard , which of the following is a correct replacement for /* construct each BingoCard */ ? I for (BingoCard card : players) card = new BingoCard(); II for (BingoCard card : players) players[card] = new BingoCard(); III for (int i = 0; i < players.length; i++) players[i] = new BingoCard();
I and II only
whenever arr contains at least one negative integer
III only
System.out.println(a.getName());
Explanation:
Correct answer: III only
Question 4
Which of the following initializes an 8 × 10 matrix with integer values that are perfect squares? (0 is a perfect square.) I int[][] mat = new int[8][10]; II int[][] mat = new int[8][10]; for (int r = 0; r < mat.length; r++) for (int c = 0; c < mat[r].length; c++) mat[r][c] = r * r; III int[][] mat = new int[8][10]; for (int c = 0; c < mat[r].length; c++) for (int r = 0; r < mat.length; r++) mat[r][c] = c * c;
II and III only
III only
II only
I and II only
Explanation:
Correct answer: I and II only
Question 5
Consider the following method that will alter the matrix mat : /** @param mat the initialized matrix * @param row the row number */ public static void matStuff(int[][] mat, int row) { int numCols = mat[0].length; for (int col = 0; col < numCols; col++) mat[row][col] = row; } Suppose mat is originally 1 4 9 0 2 7 8 6 5 1 4 3 After the method call matStuff(mat,2) , matrix mat will be
A
System.out.println(student.getAddress().getName());
A run-time error will occur.
III only
Explanation:
Correct answer: A

Ready to test your knowledge?

Buy Now to Access

Additional Information

AP CSP Practice Test - Unit 6 Array, Unit 7 ArrayList and Unit 8 2D Array

This practice set contains 36 questions from the matching question bank and focuses on public, string, return, private, and double. Work through each question carefully, review the provided solutions, and revisit topics that need more study before your next attempt.

This is an independent study resource intended for practice and review; it is not an official examination or an endorsement by any organization named in the title.

Frequently Asked Questions

This quiz contains a total of 36 practice questions carefully selected to test your knowledge on this subject.
Yes, you will have exactly 0 minutes to complete the exam. A countdown timer will be visible once you start.
Yes, you can retake this practice test as many times as you need. The questions and options may be randomized on subsequent attempts to ensure comprehensive learning.

Reviews

5.0

Based on 0 reviews

Leave a Review

No reviews yet. Be the first to review!