1: A Geographic Distance Calculator
Write an application to calculate a table of geographic distances. The input of your application is a file containing
the coordinates of cities in latitude / longitude pairs, where latitude and longitude are given in degrees and minutes,
as in:1
Edinburgh 55;57N 03;13W
London 51;30N 0;30W
NorthWalsham 52;50N 01;22E
Norwich 52;38N 01;18E
Notice that 1 degree = 60 minutes. The output should be a text fille containing a table of geographic distances in
kilometres:
Edinburgh 0.00 520.90 452.43 467.11
London 520.90 0.00 194.50 175.33
NorthWalsham 452.43 194.50 0.00 22.57
Norwich 467.11 175.33 22.57 0.00
The application should take the names of the input fille (giving the latitude / longitude coordinates) and the output
fille (into which the distance table is written) from the first and second command line parameter. For example, if
your project is called geodist and your input file is cities.txt, the command line
java -jar geodist.jar cities.txt distances.txt
should write the distance table into distances.txt.
The procedure for calculating distances in kilometres is: One degree of latitude corresponds to 111 kilometres. One
degree of longitude corresponds to 111 . cos(') kilometres, where ' is the latitude.2 For example, the coordinates
of Norwich in kilometres are (111 . 1:3 . cos(52:63 degrees) = 87:57 kilometres east of Greenwich's longitude, 111 .
52:63 = 5842:28 kilometres north of the equator), those of North Walsham are (91:64, 5864:48).
The Euclidean distance between these two is
Square.route(87 :57- 91:64)^2 + (5842:28- 5864:48)^2 = square.route(-4:07)^2 + (-22:2)^2 = 22:57
Your application should comprise a class that adequately represents the geographic location of a city
and provides good support for carrying out this calculation.
Write an application to calculate a table of geographic distances. The input of your application is a file containing
the coordinates of cities in latitude / longitude pairs, where latitude and longitude are given in degrees and minutes,
as in:1
Edinburgh 55;57N 03;13W
London 51;30N 0;30W
NorthWalsham 52;50N 01;22E
Norwich 52;38N 01;18E
Notice that 1 degree = 60 minutes. The output should be a text fille containing a table of geographic distances in
kilometres:
Edinburgh 0.00 520.90 452.43 467.11
London 520.90 0.00 194.50 175.33
NorthWalsham 452.43 194.50 0.00 22.57
Norwich 467.11 175.33 22.57 0.00
The application should take the names of the input fille (giving the latitude / longitude coordinates) and the output
fille (into which the distance table is written) from the first and second command line parameter. For example, if
your project is called geodist and your input file is cities.txt, the command line
java -jar geodist.jar cities.txt distances.txt
should write the distance table into distances.txt.
The procedure for calculating distances in kilometres is: One degree of latitude corresponds to 111 kilometres. One
degree of longitude corresponds to 111 . cos(') kilometres, where ' is the latitude.2 For example, the coordinates
of Norwich in kilometres are (111 . 1:3 . cos(52:63 degrees) = 87:57 kilometres east of Greenwich's longitude, 111 .
52:63 = 5842:28 kilometres north of the equator), those of North Walsham are (91:64, 5864:48).
The Euclidean distance between these two is
Square.route(87 :57- 91:64)^2 + (5842:28- 5864:48)^2 = square.route(-4:07)^2 + (-22:2)^2 = 22:57
Your application should comprise a class that adequately represents the geographic location of a city
and provides good support for carrying out this calculation.
Comment