Chapter 1
Chapter 1
Be Prepared
for the
Gary Litvin
Skylight Publishing, Andover, Massachusetts
Copyright 2009 by Maria Litvin, Gary Litvin, and Skylight Publishing All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the author and Skylight Publishing. Library of Congress Control Number: 2009904716 ISBN 978-0-9824775-0-2
Skylight Publishing 9 Bartlet Street, Suite 70 Andover, MA 01810 web: e-mail: www.skylit.com [email protected] [email protected]
1 2 3 4 5 6 7 8 9 10
14 13 12 11 10 09
3 hours
Exam materials given to you at the exam will include a booklet containing the needed case study code and Quick Reference a list of the library classes and their methods included in the AP subset. These materials are provided for reference it is expected that you will already be very familiar and comfortable with the case study and the required library classes before the exam. www.skylit.com/beprepared/ has current links to these materials.
The multiple-choice section is a mixture of questions related to general computer science terms, program design decisions, specific elements of Java syntax, properties of classes, logical analysis of fragments of Java code, OOP concepts, and five-six questions related to the case study. The free-response questions usually aim to cover a wide range of material: one- and two-dimensional arrays, strings, classes and interfaces, Java library classes (within the AP subset), and so on. In past exams, students have not been asked to write complete programs. Usually, they were asked to write a constructor or a method that performs a specified task under a given header for the method. The second part of the question often refers to the class or method implemented in the first part, but each part is graded separately, and your implementation of Part (a) does not have to be correct in order for you to get full credit for Part (b). Part (c) may ask questions about your implementation or ask you to write an additional method that uses Parts (a) and/or (b). In that case you are to assume that the methods in the previous parts work as intended, regardless of what you wrote for them. Free-response questions may also include a design question, in which you are asked to design a small class, then write it or some fragments of it or just use it in other parts of the question. Your design will be graded based on the appropriateness of the features of your class, appropriate names for methods and variables, and other criteria. One free-response question is based on the case study. It may ask you to extend a case study class and to write a new method or rewrite an existing method.
boolean, int, and double primitive data types. (int) and (double) casts. Other primitive data types, including char, are not in the subset and should
Assignment (=), arithmetic (+, -, *, /, %), increment/decrement (++, --), compound assignment (+=, -=, *=, /=, %=), relational (<, >, <=, >=, ==, !=), and logical (&&, ||, !) operators. Use only the postfix form of ++ and -- (x++ or x--), and do not use them in expressions.
+ and += operators for concatenating strings. Strings compareTo, equals, length, substring, and indexOf(String s) methods. \n, \\, and \"
One- and two-dimensional arrays, array.length, arrays of objects, initialized arrays such as int[] x = {1,2,3};
if-else, for, including the for each form, for(type x : values)..., while, return. But do-while and switch are not included.
Classes. Constructors, the new operator, public and private methods, static methods, static variables and static final variables (constants), overloaded methods, null. All instance variables are private. Default initialization rules are not in the subset and wont come up on the exam. Inheritance, interfaces and abstract classes, extends, implements. Calling a superclasss constructor from a subclass (as in super(...)). Calling a superclasss method from a subclass (as in super.someMethod(...)). Passing this object to a method (as in otherObject.someMethod(this)).
NullPointerException, ArrayIndexOutOfBoundsException, ArithmeticException, IllegalArgumentException, ClassCastException.
Library classes, methods, and constants: String: length(), substring(...), indexOf(String s) Integer: Integer(int x), intValue(); Integer.MIN_VALUE and Integer.MAX_VALUE. Double: Double(double x), doubleValue() Math: abs(int x), abs(double x), pow(double base, double exp), sqrt(double x),
random()
Also understand toString methods for all objects, the equals and compareTo methods for String, Integer, and Double, and the Comparable<T> interface.
The List<E> interface and the ArrayList<E> class (see Section 2.6).
If you feel you must stray from the subset in your free-response solution, you might have misunderstood the problem and be making it harder than it is. Things that are not in the AP subset and should be avoided include the following:
Java syntax abominations, such as the ?_:_ operator and the comma operator
++ and -- in expressions (as in a[i++])
Primitive data types other than boolean, int, and double (char is not in the subset) All bit-wise logical operators Also not in the subset and will not be tested:
The switch statement, the do-while loop, continue in loops The prefix form of ++ and -- operators (++k, --k) Library classes (such as StringBuffer, Arrays, DecimalFormat, etc.), unless specifically listed in the subset checked exceptions and try-catch-finally statements
System.in and Scanner; any input and output other than System.out.print and System.out.println enum data types
1.3. Grading
The exams are graded on a scale from 1 to 5. Grades of 5 and 4 are called extremely well qualified and well qualified, respectively, and usually will be honored by colleges that give credit or placement for AP exams in computer science. A grade of 3, qualified, may be denied credit or placement at some colleges. Grades of 2, possibly qualified, and 1, no recommendation, will not get you college credit or placement. 2009 was the last year when the College Board offered two AP Computer Science exams, A and, more advanced, AB. Table 1-1 presents published statistics and grade distributions on the 2004 A and AB exams. In 2004, 13,834 candidates took the A exam and 5,807 candidates took the AB exam.
1.3 ~ GRADING
Table 1-1. 2004 grade distributions for A and AB exams The multiple-choice and free-response sections weigh equally in the final grade. The College Board uses a weighted combination of the multiple-choice (MC) and free-response (FR) scores to determine the final total score:
totalScore = MC_coeff * (countCorrect - 0.25*countWrong) + FR_coeff * FR_score;
For multiple-choice questions, one point is given for each correct answer and 1/4 point is subtracted for each wrong answer. There is no subtraction for an answer left blank. Free-response questions are graded by a group of high school teachers and college professors. Scores are based on a rubric established by the Chief Reader, Exam Leader, and Question Leaders. Each free-response question is graded out of 9 points, with partial credit given according to the rubric. The final score is obtained by adding the MC and FR weighted scores. The MC and FR coefficients are chosen in such a way that they give equal weights to the multiple-choice and free-response sections of the exam. For example, if the exam has 40 multiple-choice questions and 4 free-response questions, weights of 1.25 for multiple-choice and 1.3889 for free-response will give each section a maximum total of 50, for a maximum possible total score of 100. Four cut-off points determine the grade. Table 1-2 shows the maximum composite scores and cut-off points used for the 1999 and 2004 exams. In 2004, 79% or more correct answers on the A exam and 68% or more correct answers on the AB exam
would get you a 5. The cut-off points are determined by the Chief Reader and may vary slightly from year to year based on the score distributions and close examination of a sample of individual exams.
A Max composite score 80 (1.00 * MC + 1.1111 * FR) AP Grade 5 4 3 2 1 1999 60 - 80 45 - 59 33 - 44 25 - 32 0 - 24 2004 63 - 80 49 - 62 39 - 48 32 - 38 0 - 31 AP Grade 5 4 3 2 1 AB Max composite score 100 (1.25 * MC + 1.3889 * FR) 1999 70 - 100 60 - 69 41 - 59 31 - 40 0 - 30 2004 68 -100 56 - 67 44 - 55 35 - 43 0 - 34
Table 1-2. Score-to-grade conversion Statistical analysis of published results from the 2004 exam shows that over 98% of students who got at least 27 out of 40 on the multiple-choice section received a 4 or a 5 for the whole exam. This may or may not be true for our practice exams. You will know only after the exam!
If you took the time to read a multiple-choice question and all the answer choices but decided to skip it, take an extra ten seconds and guess. Most likely you have eliminated one or two wrong answers even without noticing. If a common paragraph refers to a group of questions and you took the time to read it, try each question in the group. Do read the question before jumping to the code included in the question.
There are a few important things to know about answering free-response questions. Remember that all free-response questions have equal weight. Dont assume that the first question is the easiest and the last is the hardest. In a nutshell: be neat, straightforward, and professional; keep your exam reader in mind; dont show off. More specifically: 1. Stay within the AP Java subset. 2. Remember that the elegance of your code does not count. More often than not, a brute-force approach is the best. You may waste a lot of time writing tricky, non-standard code and trick yourself in the process or mislead your exam reader who, after all, is only human. No one will test your code on a computer. 3. Superior efficiency of your code does not count, unless the desired performance of the solution is specifically stated in the question. 4. Remember that Parts (b) and (c) of a question are graded independently from the previous parts, and may actually be easier: Part (a) may ask you to write a method, while Part (b) or Part (c) may simply ask you to use it. It is common for method(s) specified in Part (a) to be called in subsequent parts. Do so, even if your Part (a) is incorrect or left blank. Do not re-implement code from earlier parts in later parts you will waste valuable time and may lose points for doing so.
5. Bits of good thinking count. You may not know the whole solution, but if you have read and understood the question, go ahead and write fragments of code that may earn you partial credit points. But dont spend too much time improvising incorrect code. 6. Dont waste your time erasing large portions of work. Instead, cross out your work with one neat line, but only after you have something better to replace it with. Do not cross out a solution if you have no time to redo it, even if you think it is wrong. You wont be penalized for incorrect code and may get partial credit for it. Exam readers are instructed not to read any code that you have crossed out. But if you wrote two solutions, be sure to cross one out: otherwise only the first one on the page will be graded. 7. Read the comment above the method header quickly it usually restates the task in a more formal way and sometimes gives hints. Assume that all preconditions are satisfied dont add unnecessary checks to your code. 8. One common mistake is to forget a return statement in a non-void method. Make sure the returned value matches the specified type. 9. Do not ignore any hints in the question description. If an algorithm is suggested for a method (as in you may use the following algorithm), dont fight it, just do it! If the description says you may use a helper method, be sure to write and use one: chances are it is much more difficult to come up with a solution without a helper method. 10. Remember that the exam readers grade a vast number of exams in quick succession during a marathon grading session every June. Write as neatly as possible. Space out your code (dont save paper). 11. Always indent your code properly. This helps you and your exam reader. If you miss a brace but your code is properly indented, the reader (as opposed to a Java compiler) may accept it as correct. Similarly, if you put each statement on a separate line, a forgotten semicolon may not be held against you. 12. Follow the Java naming style: the names of all methods, variables, and parameters start with a lowercase letter. Use meaningful, but not too verbose, names for variables. count may be better than a; sum may be better than temp; row, col may be better than i, j. But k is better than loopControlVariable. If the question contains examples of code with names, use the same names when appropriate.
13. Dont bother with comments; they do not count and you will lose valuable time. Occasionally you can put a very brief comment that indicates your intentions for the fragment of code that follows. For example:
// Find the first empty seat: ... ...
14. Dont worry about imports assume that all the necessary library classes are imported. 15. Code strictly according to the specifications and preconditions. Avoid extraneous bells and whistles you will lose points. Never add System.out.print/println in solutions unless specifically asked to do so. 16. Use recursion when appropriate: if specifically requested or especially tempting. 17. Dont try to catch the exam authors on ambiguities: there will be no one to hear your case, and youll waste your time. Instead, try to grasp quickly what was meant and write your answer. 18. Dont quit until the time is up. Use all the time you have and keep trying. The test will be over before you know it.