Writing Code on the AP Computer Science Exams: Important Advice for Students
A Human Process
It is a nice sunny day in May. You have been learning and preparing for an intense three hours of computer science testing for the past few months. You paced yourself through the multiple-choice questions and now you are pushing through the second half of the exam, the free-response section. You tackle each problem, writing code and more code, and complete the four problems. Now you have a few minutes to spare, so you go back and look at your answers. You think the answers you have put into the exam booklet are correct; you put the pencil down and prepare for a well-deserved break. This sounds like a great testing experience; however, you need to realize that your code is not just going to be fed into some marvelous scanner/compiler that can decipher any form of written communication and convert it into executable Java® bytecode. That stuff you just put onto paper will be read by a real live human being. This person is going to have to determine if your s is perhaps a g or if that slight misspelling of a variable name is accidental or a case of a confused identifier. We AP Exam Readers recognize that you are in a rush to complete an intense exam. However, you will definitely benefit from taking time to consider a few key strategies to better prepare your exam for the wonderful grade you feel it deserves. As you might know, the questions are scored on a rubric system to ensure that the fairest scoring is done on every exam (19,000 and change in 2005) and that the scoring is consistent. Three areas worth keeping in mind as you prepare your paper for the Readers are character size and penmanship, naming conventions, and avoidable mistakes.
Character Size and Penmanship
Print or write your code at a reasonable size. Those not-so-perfectly formed letters that are less than a quarter of an inch in height are great for fitting an hour-long lecture onto a limited supply of paper. However, this small penmanship is not a pleasure to read when trying to trace through code. This is especially true for the Readers of your exam. Remember, these people are reading many exams and their eyes do in fact get tired. A good character size is between one-half and one centimeter, or, for those who haven't adjusted to the metric system, between a quarter and a half inch or so. You should also make sure that your penmanship is clear enough to express the code adequately. Below is a good example of readable penmanship and character size.
public class Advance extends Ticket () { private.double price; public Advance (int daysInAdvence) { if (daysInAdvance > 9) price=30; else price=40; } public double getPrice() {return price; } }
This sample and others can be found in the AP Computer Science 2005 Sample Student Responses.
- AP Computer Science A 2005 Sample Student Responses (.pdf/772KB)
Naming Conventions
This idea ties directly into the rules of good software design. Do not use single-letter variable names, except for looping variables. Choose variable names that reflect the variable's purpose or the scope of its use. An example of good variable naming can be seen in the following code sample:
Set AlphaCity = new TreeSet();
Versus
Set x = new HashSet();
This principle is especially important in a design question. When you are using multiple data structures or passing information to different methods, very short variable representations can easily be confused when you go back to check your answers. One of the biggest mistakes in this area is naming something o, which can cause confusion when you do any looping or value changing. Do you want to add 0 to an Integer
or o to a String
representation? When reading typed text on paper or on the Web, the meaning is obvious, but remember that handwriting and print are not TrueType® fonts.
Avoidable Mistakes
Other basic issues to keep in mind are the mistakes that can cause points to be deducted from your score for a question. There are three types of usage errors in student responses: no deduction, 1/2-point deduction, and 1-point deduction.
The no-deduction errors include missing parentheses around an if or while condition, a missing } where indentation is clear, use of = instead of = =, and a missing semicolon at the end of a statement. These errors are usually honest slips of the mind in a stressful, time-intensive situation and should not cause you the test-taker any worry. However, correct indentation and use of braces will make it easy for the Reader to interpret your answer.
Half-point deductions are for minor errors. These errors include misspellings of identifiers, confusion between [ ] and get methods, and failure to declare local variables. These errors can often be avoided by simply working out your answer in some form before you actually write down your final solution. Practice writing code by hand regularly to prepare yourself for the exam.
Finally, the major errors cause a 1-point deduction. These often include unneeded output/input statements (extraneous code), confused scope or object/method relationships, misuse of private data, and the destruction of data structures. As you can see, most of these errors are serious enough that they cause problems with code and show a lack of understanding of the object-oriented paradigm. To avoid these errors, make sure you understand what is being asked in the question. Read the pre- and post-conditions; often the comments give hints to the solution. If you have been successful over the course of your AP class up to now, you should not have many problems in this area.
There are also built-in help files available to you throughout the entire exam. Don't ignore them. You are provided with the case study documentation files and code. Use these resources to see examples of how to write proper code. There is a reason we have been pushing you to talk with the fish
ies all year. In the case of massive brain failure while taking the AP Exam, the case study supplemental files contain examples of the proper way to use loops, instantiate and declare data structures, and other basic Java conventions. This information is included with the exam for a reason; do not be afraid to use these resources.
We hope to see you all do well on the exam and we hope that you will continue to enjoy your work in computer science.
Authored by
Cody Henrichsen
Granger High School
West Valley City, Utah