Beruflich Dokumente
Kultur Dokumente
The materials included in these files are intended for noncommercial use by
AP teachers for course and exam preparation; permission for any other use
The College Board is a not-for-profit membership association whose mission is to connect students to college success and opportunity.
Founded in 1900, the association is composed of more than 4,500 schools, colleges, universities, and other educational organizations. Each year, the
College Board serves over three million students and their parents, 23,000 high schools, and 3,500 colleges through major programs and services in
college admissions, guidance, assessment, financial aid, enrollment, and teaching and learning. Among its best-known programs are the SAT, the
PSAT/NMSQT, and the Advanced Placement Program (AP). The College Board is committed to the principles of
excellence and equity, and that commitment is embodied in all of its programs, services, activities, and concerns.
For further information, visit www.collegeboard.com
Copyright 2004 College Entrance Examination Board. All rights reserved. College Board, Advanced Placement Program, AP, AP Central,
AP Vertical Teams, APCD, Pacesetter, Pre-AP, SAT, Student Search Service, and the acorn logo are registered trademarks of the
College Entrance Examination Board. PSAT/NMSQT is a registered trademark jointly owned by the
College Entrance Examination Board and the National Merit Scholarship Corporation.
Educational Testing Service and ETS are registered trademarks of Educational Testing Service.
Other products and services may be trademarks of their respective owners.
For the College Boards online home for AP professionals, visit AP Central at apcentral.collegeboard.com.
(a) Write the WordList method numWordsOfLength. Method numWordsOfLength returns the
number of words in the WordList that are exactly len letters long. For example, assume that the
instance variable myList of the WordList animals contains the following.
["cat", "mouse", "frog", "dog", "dog"]
The table below shows several sample calls to numWordsOfLength.
Call
animals.numWordsOfLength(4)
animals.numWordsOfLength(3)
animals.numWordsOfLength(2)
animals.removeWordsOfLength(4);
animals.removeWordsOfLength(3);
["mouse"]
animals.removeWordsOfLength(2);
["mouse"]
Note that a Cat is-a Pet, a Dog is-a Pet, and a LoudDog is-a Dog.
The class Pet is specified as an abstract class as shown in the following declaration. Each Pet has a name
that is specified when it is constructed.
public abstract class Pet
{
private String myName;
public Pet(String name)
{ myName = name; }
public String getName()
{ return myName; }
public abstract String speak();
}
The subclass Dog has the partial class declaration shown below.
public class Dog extends Pet
{
public Dog(String name)
{ /* implementation not shown */
0
1
1
1
>
2
2
3
2
right wall
The following sequence shows the configuration of the hallway and the robot after each move.
After move 1
0 1
2
3
1 0
2
2
>
0
1
0
0
>
After move 5
1
2
3
0
0
0
<
After move 2
0 1 2 3
1 0 1 2
>
0
1
After move 3
0 1 2 3
1 0 0 2
>
After move 6
1 2 3
0 0 0
<
0
1
After move 7
1 2 3
0 0 0
<
After move 4
0 1 2 3
1 0 0 1
>
0
1
<
After move 8
1 2 3
0 0 0
After move 9
1
2
3
0
0
0
After nine moves, the robot stops because the hall is clear.
END OF EXAMINATION
11