Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Java Help

Ghost
Ghost 


Requirements: So i finished working on this but my project keeps giving me error message doesn't run. It does do some of the requirements but not all. Build your project in NetBeans using the Run - Build Project, or Run - Clean and Build Project menu item. 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. See the sample input file. 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"); System.exit(99); } Cruncher dataManipulator = new Cruncher(args[0], args[1]); dataManipulator.openFiles(); dataManipulator.findDistance(); dataManipulator.writeRecords(); dataManipulator.closeFiles(); } Here is a sample input file and a sample output file. 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 Attachments Tags Clarifications

Answers

Java Cruncher

SW_wizard
SW_wizard 



Netbeans project and jar file attached Attachments
CruncherJava_NB.zip (24 K) Download









Preview
for junit execution -init-macrodef-debug: defines macro for class debugging -init-macrodef-java: defines macro for class execution -do-jar-with-manifest: JAR building (if you are using a manifest) -do-jar-without-manifest: JAR building (if you are not using a manifest) run: execution of project -javadoc-build: Javadoc generation test-report: JUnit

Preview
Newfoundland:Burlington:49? 45' N:56? 1' W Ontario:Burlington:43? 20' N:79? 48' W Ontario:Waterloo:43? 30' N:80? 32' W Quebec:Waterloo:45? 21' N:72? 31' W British Columbia:Kamloops:50? 40' N:120? 21' W Ontario:Markham:43? 53' N:79? 15' W Ontario:Guelph:43? 33' N:80? 15' W Ontario:Oshawa:43? 54' N:78? 51' W Ontario:Peterborough:44? 18' N:78? 20' W Nunavut:Alert:82? 28' N:62? 18'

Preview
</not> </condition> </fail> <target depends="test,jar,javadoc" description="Build and test whole project." name="default"/> <!-- ====================== INITIALIZATION SECTION ====================== --> <target name="-pre-init"> <!-- Empty placeholder for easier customization. --> <!-- You can override this target in the ../build.xml file. -->

Preview
version="1.0" encoding="UTF-8"?> <project xmlns="http://www.netbeans.org/ns/project/1"> <type>org.netbeans.modules.java.j2seproject</type> <configuration> <data

Preview
9' N:80o 15' W Ontario:Pickering:43o 50' N:79o 6' W Ontario:Barrie:44o 23' N:79o 42' W Ontario:Richmond:45o 12' N:75o 50' W Ontario:Sudbury:46o 29' N:80o 60' W Ontario:Burlington:43o 20' N:79o 48' W Ontario:Waterloo:43o 30' N:80o 32' W Ontario:Brockville:44o 36' N:75o 41' W Ontario:Hamilton:43o 15' N:79o 52' W Prince Edward Island:Victoria:46o 13' N:63o 28'

Preview
@return * An integer value, -1,0,1. */ public int compare(CityNode cityNode) { if(province.compareToIgnoreCase(cityNode.province) < 0) return -1; else if(province.compareToIgnoreCase(cityNode.province) == 0) { if(city.compareToIgnoreCase(cityNode.city) < 0) return -1; if(city.compareToIgnoreCase(cityNode.city) == 0) return 0; } else

Preview
CityNode firstCity = new CityNode(); CityNode secondCity = new CityNode(); Scanner sc = new Scanner(System.in); System.out.print("Enter the name of first city: "); firstCity.city = sc.nextLine(); System.out.print("Enter the name of first province: "); firstCity.province = sc.nextLine(); System.out.print("Enter the name of second

Preview
dataManipulator = new Cruncher(args[0], args[1]);*/ Cruncher dataManipulator = new Cruncher("input.txt", "sortedData1.txt"); //- for testing dataManipulator.openFiles(); dataManipulator.findDistance();

JAR_forCruncher.zip (6 K) Download

Preview
W British Columbia:Vancouver:49? 17' N:123? 8' W Ontario:Ottawa:45? 26' N:75? 42' W Alberta:Edmonton:53? 33' N:113? 30' W Alberta:Calgary:51? 2' N:114? 4' W Nova Scotia:Halifax:44? 40' N:63? 36' W Manitoba:Winnipeg:49? 54' N:97? 8' W British Columbia:Victoria:48? 25' N:123? 22' W Newfoundland:Victoria:47? 46' N:53? 13' W Ontario:Victoria:43? 46' N:79? 52' W Prince

Screenshots
Purchase Answer