Graphic by Keith Ohlfs

CS111, Wellesley College, Fall 1997

Prelab #3
[CS111 Home Page] [Syllabus] [Students] [Lecture Notes] [Assignments] [Programs] [Documentation] [Software Installation] [FAQ] [CS Dept.] [CWIS]

CS111 Prelab #3: Debugging

Due Date: Before lab, September 22 or 23.

Dealing with Common Errors (Bugs)

When programming in Java, you will often make mistakes typing or designing your program code. These mistakes will lead to two types of errors: Compiler errors, which cause error messages during the compilation of your program, and run-time errors, which allow the program to compile, but cause it to do the wrong thing. These errors are often called "bugs". Knowing how to find and correct bugs in your code (known as debugging) is an extremely important skill for a programmer. In lab we examined some common types of errors. Some common errors are as follows:

In this prelab, you will get some practice debugging some java source code. The code was written to display CS111 in block letters as follows:

However, your lab instructor was up very late at night preparing for the lab and being rather sleepy, she made some errors (less than 10) when writing the code. Your mission is to find the errors and correct the code for her. Here's how to get started:

1. In the download subdirectory of the cs111 folder on Nike, there is a folder called buggyCode. Use Fetch to download this folder to your Macintosh. This folder contains 3 items.

2. Once you have downloaded the folder to the desktop, open the project file by double-clicking on it. This should start-up the Symantec Project Manager, and a project window should appear on the screen. If this does not happen, you may have the fetch preferences set incorrectly. Try reinstalling the fetch preferences on your computer and downloading again. If it still does not work, please seek help from Lyn or Stanzi or a Tutor. This part of the prelab is not supposed to be one of the bugs!

3. Open the java source file by double clicking on the name CS111stick.java in the project window.

4. Try to build the applet code by choosing "Bring up to date..." from the Build menu.

5. A window will appear titled "Build Errors for CS111stick.proj". Several errors will be listed in this window. Note that the compiler will not necessarily report all the errors in the code. Also note that it may not correctly determine what the error is.

6. Double click on one of the error messages. The project manager will highlight the line in the source code in which it perceived an error. This is a good place to start looking for the error, but keep in mind that the error might occur in one of the lines above the line the compiler highlights. If you do not understand the error message, try looking for typographical errors of the sort mentioned above.

7. When you discover an error, correct the code in the .java file and try "Bring up to date..." again. (Make sure you save your corrected file first). You will find that sometimes fixing one typographical error will eliminate 2 or more error messages. However, some new error messages may appear after you fix an error.

8. Create a separate textfile, called Errors.txt (Choose "New" from the File menu) and in it write down what the error was and which line it occured on. E.g. you might say "Line 28 was missing a semicolon" if that was the case. Save this textfile.

9. Repeat steps 6 through 8 until the program compiles.

10. Look at the applet by running the AppletViewer and choosing "Open Local" to open the CS111stick.html file. You will find that there are some run-time errors.

11. Correct the run-time errors in the source code, and write down what errors you found and what line they occured on in Errors.txt.

12. When you are finished, make sure the buggyCode folder contains the following items:

13. Upload the buggyCode folder into your directory in the lab3 subdirectory of the CS111 drop folder.

Reminder

If you have spent 2 hours on this prelab and not finished it, write a sentence at the end of Errors.txt stating why you were not able to finish and turn in as much as you have done.