Build your project in NetBeans using the Run - Build Project, or Run - Clean and Build Project menu
From the dist directory you will execute your program from the command line with two filenames as
arguments, input file name and output file name. For example:
java -jar lab5.jar..\input.txt ..\output.txt
Write a java program that will prompt the user for two city and province names from a select list.
Read each of the records from the input file and extract the two records that match those
requrested by the user.
Define a class named Cruncher which will do all the 'heavy lifting' in this program.
The main line of your solution will look exactly like this:
public static void main(String args)
if(args.length < 2)
System.err.println("Usage: java -jar lab5.jar infile outfile");
Cruncher dataManipulator = new Cruncher(args, args);
Latitude is measured in degrees and minutes with zero at the equator and 90 degress at the North pole or South pole. Latitude has to be expressed as North or South. There is usually a third number, seconds but it is not in our data, just degrees and minutes. Longitude is also measured in degrees and minutes with zero located a little outside London England (Greenwich). Longitude must be expressed as West or East and it ranges from zero to 180 degrees. All the data in Canada will be North and West and simplifies our calculation a little bit.
Here is the code to calculate the distance between two cities given longitude and latitude:
double earthRadius = 6371; // in km
double distance = Math.acos(Math.sin(Lat1) * Math.sin(Lat2) +
Math.cos(Lat1) * Math.cos(Lat2) *
Math.cos(Long2 - Long1)) * earthRadius;
The values you feed into the trig functions are in radians. You will be reading
strings of text in degrees and minutes. So your program will have to convert
strings to doubles as degrees and minutes and then convert those doubles to
decimal degrees and then convert that to radians. Here is a non-Java
description of what I mean:
degree = 23
minute = 45
decimaldegree is then 23.75 because there are 60 minutes in a degree ( our data does not have seconds )
radians = decimaldegree * PI/180