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?
Correct Answer:
for (Ticket t : tickList) total += t.getPrice();
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?
Correct Answer:
6, 4, 2
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();
Correct Answer:
III only
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;
Correct Answer:
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
Correct Answer:
A
Explanation:
Correct answer: A
Question 1
Exam overview

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.

More details

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.

Quiz information

Frequently Asked Questions

The complete question count is available after full access is unlocked.
No fixed duration is currently configured for this quiz.
Question explanations are included where they are available in the quiz content, helping you review the reasoning after answering.
Yes. You can retake the practice test again as you continue studying during your available access period.
After your access is confirmed, you can continue into the complete practice exam from this quiz flow.
Unless explicitly stated otherwise, this page provides independent practice material for study and exam preparation and is not the official examination itself.
Keep studying

Related Questions