When you write a program that processes a large data file, the debugger
can be particularly helpful to allow you to see what's going on. We are
going to debug the ZipLookup program that you downloaded
from the class web page.
This program makes two passes through the data file. First it looks for
the target zip code in the method named find. Then it
shows all matches in the method named showMatches. We want
to debug showMatches.
The data file has a total of 43,191 zip codes in it, so it is not practical to have it display all of the data. That's why it's important to have good debugging skills to be able to selectively stop the program at certain points to see what is going on. This will be a helpful skill when you work on the programming assignment.
Ask a TA for help if you have trouble setting or clearing break points or otherwise completing this exercise.
continued on the next slide...
What zip code are you interested in? 20500
And what proximity (in miles)? 0.3
20500: Washington, DC
zip codes within 0.3 miles:
20045 Washington, DC, 0.26 miles
20500 Washington, DC, 0.00 miles
20501 Washington, DC, 0.27 miles
20502 Washington, DC, 0.27 miles
while loop in
the showMatches method executes. Set a break point on the
while loop itself. Then debug to find lat1
and long1 (latitude and longitude of the White House zip
code).
lat1 |
38.894781 |
|
long1 |
-77.036122 |
continued on the next slide...
Clear your previous break point and set a new break point inside on
the printf inside the if. Then hit the resume
button that looks like a play button and fill in the table below with the
values for zip, lat2, and long2.
zip |
lat2 |
long2 |
|---|---|---|
| 20045 | 38.896599 | -77.0319 |
| 20500 | 38.894781 | -77.036122 |
| 20501 | 38.89872 | -77.036198 |
| 20502 | 38.89872 | -77.036198 |