Java Reference
In-Depth Information
The code for opening a file is fairly standard and could be used without modifica-
tion in many programs. We refer to this as boilerplate code .
Boilerplate Code
Code that tends to be the same from one program to another.
The getInput method is a good example of the kind of boilerplate code that you
might use in many different file-processing programs.
6.5 Case Study: Zip Code Lookup
Knowing the distance between two locations turns out to extremely helpful and valu-
able. For example, many popular Internet dating sites allow you to search for people
on the basis of a target location. On Yahoo! Personals, you can search for potential
matches within a particular radius of a given city or zip code (5 miles, 10 miles,
15 miles, 25 miles, and so on). Obviously this is an important feature for a dating site
because people are most interested in dating other people who live near them.
There are many other applications of this kind of proximity search. In the 1970s
and 1980s there was an explosion of interest in what is known as direct mail market-
ing that has produced what we now call junk mail. Proximity searches are very
important in direct mail campaigns. A local store, for example, might decide to mail
out a brochure to all residents who live within 5 miles of the store. A political candi-
date might pay a membership organization like The Sierra Club or the National Rifle
Association a fee to get the mailing addresses of all its members who live within a
certain distance of a town or a city district.
Massive databases keep track of potential customers and voters. Direct-mail mar-
keting organizations often want to find the distance between one of these individuals
and some fixed location. The distance calculations are done almost exclusively with
zip codes. There are over 40,000 five-digit zip codes in the United States. Some zip
codes cover rural areas that are fairly large, but more often a zip code determines
your location in a city or town to within a fraction of a mile. If you use the more spe-
cific Zip
4 database, you can often pinpoint a location to within a few city blocks.
If you do a web search for “zip code database” or “zip code software” you will
find that there are many people selling the data and the software to interpret the data.
There are also some free databases, although the data aren't quite as accurate. The
U.S. Census Bureau is the source of much of the free data.
To explore this application, let's write a program that finds all the zip codes within
a certain proximity of another zip code. A web site like Yahoo! Personals could use the
logic of this program to find potential dates within a certain radius. You'd simply start
with the zip code of interest, find all the other zip codes within a particular distance,
and then find all the customers who have those zip codes. We don't have access to a
massive dating database like Yahoo! Personals, so we'll be working on just the first
part of this task, finding the zip codes that are within a specified distance.
 
 
Search WWH ::




Custom Search