{"id":17537,"date":"2021-07-16T19:34:06","date_gmt":"2021-07-16T19:34:06","guid":{"rendered":"https:\/\/papersspot.com\/blog\/2021\/07\/16\/cruncher-java\/"},"modified":"2021-07-16T19:34:06","modified_gmt":"2021-07-16T19:34:06","slug":"cruncher-java","status":"publish","type":"post","link":"https:\/\/papersspot.com\/blog\/2021\/07\/16\/cruncher-java\/","title":{"rendered":"Cruncher.java"},"content":{"rendered":"<p>From the dist directory you will execute your program from the command line with two filenames asarguments, input file name and output file name. For example: <br \/>java -jar lab5.jar..input.txt ..output.txt <br \/>Write a java program that will prompt the user for two city and province names from a select list. <br \/>Read each of the records from the input file and extract the two records that match thoserequrested by the user. <br \/>Define a class named Cruncher which will do all the &#8216;heavy lifting&#8217; in this program. <br \/>The main line of your solution will look exactly like this: <br \/>public static void main(String[] args) { \u00a0 if(args.length &lt; 2) \u00a0 { \u00a0 System.err.println(&quot;Usage: java -jar lab5.jar infile outfile&quot;); \u00a0 System.exit(99); \u00a0 } \u00a0 Cruncher dataManipulator = new Cruncher(args[0], args[1]); \u00a0 dataManipulator.openFiles(); \u00a0 dataManipulator.findDistance(); \u00a0 dataManipulator.writeRecords(); \u00a0 dataManipulator.closeFiles(); } <br \/>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. <br \/>Here is the code to calculate the distance between two cities given longitude and latitude: <br \/>double earthRadius = 6371;\u00a0 \/\/ in km\u00a0 double distance = Math.acos(Math.sin(Lat1) * Math.sin(Lat2) \u00a0 Math.cos(Lat1) * Math.cos(Lat2) *\u00a0 Math.cos(Long2 &#8211; Long1)) * earthRadius;The values you feed into the trig functions are in radians. You will be readingstrings of text in degrees and minutes. So your program will have to convertstrings to doubles as degrees and minutes and then convert those doubles todecimal degrees and then convert that to radians. Here is a non-Javadescription of what I mean: <br \/>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 <\/p>\n","protected":false},"excerpt":{"rendered":"<p>From the dist directory you will execute your program from the command line with two filenames asarguments, 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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[20],"class_list":["post-17537","post","type-post","status-publish","format-standard","hentry","category-research-paper-writing","tag-programming"],"_links":{"self":[{"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/posts\/17537","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/comments?post=17537"}],"version-history":[{"count":0,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/posts\/17537\/revisions"}],"wp:attachment":[{"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/media?parent=17537"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/categories?post=17537"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/tags?post=17537"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}