AP Computer Science A 2015 Free-Response Questions

AP? Computer Science A 2015 Free-Response Questions

? 2015 The College Board. College Board, Advanced Placement Program, AP, AP Central, and the acorn logo are registered trademarks of the College Board. Visit the College Board on the Web: . AP Central is the official online home for the AP Program: apcentral..

2 AP? COMPUTER SCIENCE A FREE-RESPONSE QUESTIONS

COMPUTER SCIENCE A SECTION II

Time--1 hour and 45 minutes Number of questions--4 Percent of total score--50

Directions: SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA.

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.

1. This question involves reasoning about one-dimensional and two-dimensional arrays of integers. You will write three static methods, all of which are in a single enclosing class, named DiverseArray (not shown). The first method returns the sum of the values of a one-dimensional array; the second method returns an array that represents the sums of the rows of a two-dimensional array; and the third method analyzes row sums.

(a) Write a static method arraySum that calculates and returns the sum of the entries in a specified one-dimensional array. The following example shows an array arr1 and the value returned by a call to arraySum.

arr1

Value returned by arraySum(arr1)

0

1

2

3

4

1

3

2

7

3

16

WRITE YOUR SOLUTION ON THE NEXT PAGE.

? 2015 The College Board. Visit the College Board on the Web: .

GO ON TO THE NEXT PAGE. -2-

2 AP? COMPUTER SCIENCE A FREE-RESPONSE QUESTIONS

Complete method arraySum below.

/** Returns the sum of the entries in the one-dimensional array arr. */

public static int arraySum(int[] arr)

Part (b) begins on page 4.

? 2015 The College Board. Visit the College Board on the Web: .

GO ON TO THE NEXT PAGE. -3-

2 AP? COMPUTER SCIENCE A FREE-RESPONSE QUESTIONS

(b) Write a static method rowSums that calculates the sums of each of the rows in a given twodimensional array and returns these sums in a one-dimensional array. The method has one parameter, a twodimensional array arr2D of int values. The array is in row-major order: arr2D[r][c] is the entry at row r and column c. The method returns a one-dimensional array with one entry for each row of arr2D such that each entry is the sum of the corresponding row in arr2D. As a reminder, each row of a two-dimensional array is a one-dimensional array.

For example, if mat1 is the array represented by the following table, the call rowSums(mat1) returns the array {16, 32, 28, 20}.

mat1

0

1

2

3

4

0

1

3

2

7

3

1

10 10

4

6

2

2

5

3

5

9

6

3

7

6

4

2

1

Methods written in this question

public static int arraySum(int[] arr) public static int[] rowSums(int[][] arr2D) public static boolean isDiverse(int[][] arr2D)

WRITE YOUR SOLUTION ON THE NEXT PAGE.

? 2015 The College Board. Visit the College Board on the Web: .

GO ON TO THE NEXT PAGE. -4-

2 AP? COMPUTER SCIENCE A FREE-RESPONSE QUESTIONS

Assume that arraySum works as specified, regardless of what you wrote in part (a). You must use arraySum appropriately to receive full credit. Complete method rowSums below. /** Returns a one-dimensional array in which the entry at index k is the sum of

* the entries of row k of the two-dimensional array arr2D. */ public static int[] rowSums(int[][] arr2D)

Part (c) begins on page 6.

? 2015 The College Board. Visit the College Board on the Web: .

GO ON TO THE NEXT PAGE. -5-

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download

To fulfill the demand for quickly locating and searching documents.

It is intelligent file search solution for home and business.

Literature Lottery

Related searches