# 2008 AP Computer Science A 计算机科学A真题系列之选择题免费下载

### 2008 计算机科学A选择题部分免费下载

#### 部分真题预览：

8）A car dealership needs a program to store information about the cars for sale.
For each car, they want to keep track of the following information: number of doors (2 or 4), whether the car has air conditioning, and its average number of miles per gallon. Which of the following is the best design?

1. Use one class, Car, which has three data fields: int numDoors, boolean hasAir, and double milesPerGallon.
2. Use four unrelated classes: Car, Doors, AirConditioning, and MilesPerGallon.
3. Use a class Car which has three subclasses: Doors, AirConditioning, and MilesPerGallon.
4. Use a class Car, which has a subclass Doors, with a subclass AirConditioning, with a subclass MilesPerGallon.
5. Use three classes: Doors, AirConditioning, and MilesPerGallon, each with a subclass Car.

Questions 11-12 refer to the following information.

Consider the following instance variable and method findLongest with line numbers added for reference. Method findLongest is intended to find the longest consecutive block of the value target occurring in the array nums; however, findLongest does not work as intended.
For example, if the array nums contains the values [7, 10, 10, 15, 15, 15, 15, 10, 10, 10, 15, 10, 10], the call findLongest(10) should return 3, the length of the longest consecutive block of 10’s.

11) The method findLongest does not work as intended.
Which of the following best describes the value returned by a call to findLongest ?

1. It is the length of the shortest consecutive block of the value target in nums.
2. It is the length of the array nums.
3. It is the number of occurrences of the value target in nums.
4. It is the length of the first consecutive block of the value target in nums.
5. It is the length of the last consecutive block of the value target in nums.

12)Which of the following changes should be made so that method findLongest will work as intended?

1. Insert the statement lenCount = 0; between lines 2 and 3.
2. Insert the statement lenCount = 0; between lines 8 and 9.
3. Insert the statement lenCount = 0; between lines 10 and 11.
4. Insert the statement lenCount = 0; between lines 11 and 12.
5. Insert the statement lenCount = 0; between lines 12 and 13.