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.
16 5114
What have you accomplished on this problem alone? What code do you have? What ideas do you have?
I have nothing, kind of hoping some Really nice people on here could give me some ideas and help really.
I have nothing, kind of hoping some Really nice people on here could give me some ideas and help really.
Well first you need to do a design. What kind of design would you need to accomplish your task? What does the flow of information look like. At a high level what do you have to do?
- Read a file
- Tokenize and parse the input
- Do some calculations on it
- Then what?
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.
If you are clueless about a particular program try thinking if you were to do it manually instead of writing an application then how would you go about it.Jot those points down as an algorithm and then get started.Might help generate some ideas!
You better learn how to make jar files too.
I am using Netbeans 5.0 and my code so far is:
It should read in the file Geo do some stuff to see if the file exsists and then split the bits of the text file up into parts of an arraylist.
Is this the right sort of thing.
And for some reason Netbeans doesnt like some of my code, it says
"
Cannot find symbol
symbol: class Geo
location: class calculator.Main
" -
-
-
package calculator;
-
import java.io.*;
-
-
-
/**
-
*
-
* @author Matthew
-
*/
-
public class Main {
-
-
/** Creates a new instance of Main */
-
public Main() {
-
}
-
-
/**
-
* @param args the command line arguments
-
*/
-
public static void main(String[] args) {
-
BufferedReader in = getReader("Geo.txt");
-
-
Geo geo = readGeo(in);
-
while (geo != null)
-
{
-
String msg = geo.location;
-
}
-
}
-
-
-
-
private static BufferedReader getReader(String name)
-
{
-
BufferedReader in = null;
-
try
-
{
-
File file = new file(name);
-
in = new BufferedReader(
-
new FileReader(file) );
-
}
-
catch (FileNotFoundException e)
-
{
-
System.out.println("The File does not exsist");
-
System.exit(0);
-
}
-
catch (IOException e)
-
{
-
System.out.println("I/O Error");
-
System.exit(0);
-
}
-
return in;
-
}
-
-
private static Geo readGeo(BufferedReader in)
-
{
-
String location;
-
String line = "";
-
String[] data;
-
String[] data2;
-
-
try
-
{
-
line = in.readLine();
-
}
-
catch (IOException e)
-
{
-
System.out.println("I/O Error");
-
System.exit(0);
-
}
-
-
if (line == null)
-
return null;
-
else
-
{
-
data = line.split ("\t");
-
location = data[0];
-
data2 = line.split (";");
-
-
-
-
}
-
}
-
-
}
-
-
I am using Netbeans 5.0 and my code so far is:
It should read in the file Geo do some stuff to see if the file exsists and then split the bits of the text file up into parts of an arraylist.
Is this the right sort of thing.
And for some reason Netbeans doesnt like some of my code, it says
"
Cannot find symbol
symbol: class Geo
location: class calculator.Main
" -
-
-
package calculator;
-
import java.io.*;
-
-
-
/**
-
*
-
* @author Matthew
-
*/
-
public class Main {
-
-
/** Creates a new instance of Main */
-
public Main() {
-
}
-
-
/**
-
* @param args the command line arguments
-
*/
-
public static void main(String[] args) {
-
BufferedReader in = getReader("Geo.txt");
-
-
Geo geo = readGeo(in);
-
while (geo != null)
-
{
-
String msg = geo.location;
-
}
-
}
-
-
-
-
private static BufferedReader getReader(String name)
-
{
-
BufferedReader in = null;
-
try
-
{
-
File file = new file(name);
-
in = new BufferedReader(
-
new FileReader(file) );
-
}
-
catch (FileNotFoundException e)
-
{
-
System.out.println("The File does not exsist");
-
System.exit(0);
-
}
-
catch (IOException e)
-
{
-
System.out.println("I/O Error");
-
System.exit(0);
-
}
-
return in;
-
}
-
-
private static Geo readGeo(BufferedReader in)
-
{
-
String location;
-
String line = "";
-
String[] data;
-
String[] data2;
-
-
try
-
{
-
line = in.readLine();
-
}
-
catch (IOException e)
-
{
-
System.out.println("I/O Error");
-
System.exit(0);
-
}
-
-
if (line == null)
-
return null;
-
else
-
{
-
data = line.split ("\t");
-
location = data[0];
-
data2 = line.split (";");
-
-
-
-
}
-
}
-
-
}
-
-
Well you don't have a class called Geo (or have not compiled it yet) but you are trying to create an object of type Geo.
What do you want the readGeo method to do exactly.
I am using Netbeans 5.0 and my code so far is:
It should read in the file Geo do some stuff to see if the file exsists and then split the bits of the text file up into parts of an arraylist.
Is this the right sort of thing.
And for some reason Netbeans doesnt like some of my code, it says
"
Cannot find symbol
symbol: class Geo
location: class calculator.Main
" -
-
-
package calculator;
-
import java.io.*;
-
-
-
/**
-
*
-
* @author Matthew
-
*/
-
public class Main {
-
-
/** Creates a new instance of Main */
-
public Main() {
-
}
-
-
/**
-
* @param args the command line arguments
-
*/
-
public static void main(String[] args) {
-
BufferedReader in = getReader("Geo.txt");
-
-
Geo geo = readGeo(in);
-
while (geo != null)
-
{
-
String msg = geo.location;
-
}
-
}
-
-
-
-
private static BufferedReader getReader(String name)
-
{
-
BufferedReader in = null;
-
try
-
{
-
File file = new file(name);
-
in = new BufferedReader(
-
new FileReader(file) );
-
}
-
catch (FileNotFoundException e)
-
{
-
System.out.println("The File does not exsist");
-
System.exit(0);
-
}
-
catch (IOException e)
-
{
-
System.out.println("I/O Error");
-
System.exit(0);
-
}
-
return in;
-
}
-
-
private static Geo readGeo(BufferedReader in)
-
{
-
String location;
-
String line = "";
-
String[] data;
-
String[] data2;
-
-
try
-
{
-
line = in.readLine();
-
}
-
catch (IOException e)
-
{
-
System.out.println("I/O Error");
-
System.exit(0);
-
}
-
-
if (line == null)
-
return null;
-
else
-
{
-
data = line.split ("\t");
-
location = data[0];
-
data2 = line.split (";");
-
-
-
-
}
-
}
-
-
}
-
-
You might want to search the APIs for a tokenize method or string tokenizer. The way that you are reading in your file is not very object oriented.
Well you don't have a class called Geo (or have not compiled it yet) but you are trying to create an object of type Geo.
What do you want the readGeo method to do exactly.
The readGeo should read in the file that the buffered reader has, which should be geo.text and then split bits of the text file up into array parts so that i can then do some calculations on them.
If i create a new class, Geo, how do i get the main part of the code to refer to it. Netbeans is annoying!!!
You might want to search the APIs for a tokenize method or string tokenizer. The way that you are reading in your file is not very object oriented.
I dont think a tokenizer will help me with this to be honest.
The readGeo should read in the file that the buffered reader has, which should be geo.text and then split bits of the text file up into array parts so that i can then do some calculations on them.
If i create a new class, Geo, how do i get the main part of the code to refer to it. Netbeans is annoying!!!
If you create the class Geo, you need to make sure that it is on your CLASSPATH. I don't think you need to import it but you could do that also.
The readGeo should read in the file that the buffered reader has, which should be geo.text and then split bits of the text file up into array parts so that i can then do some calculations on them.
If i create a new class, Geo, how do i get the main part of the code to refer to it. Netbeans is annoying!!!
Netbeans is quite alright. I wouldn't advice beginners to use IDEs however ...
Now you don't need another class. Just a method readGeo is fine.
You want to create arrays using data that is in a file. How is the data arranged in the file and how do you want it to be stored in the arrays.
Netbeans is quite alright. I wouldn't advice beginners to use IDEs however ...
Now you don't need another class. Just a method readGeo is fine.
You want to create arrays using data that is in a file. How is the data arranged in the file and how do you want it to be stored in the arrays.
In the text file, Geo.text, the data is arranged as follows:
Edinburgh 55;57N 03;13W
London 51;30N 0;30W
NorthWalsham 52;50N 01;22E
Norwich 52;38N 01;18E
In the code before i am attempting to split each line up, like:
Edingburgh in data[0] and 55 in data[1] and so on. then i can use these to carry out some calculations for the answer.
In the text file, Geo.text, the data is arranged as follows:
Edinburgh 55;57N 03;13W
London 51;30N 0;30W
NorthWalsham 52;50N 01;22E
Norwich 52;38N 01;18E
In the code before i am attempting to split each line up, like:
Edingburgh in data[0] and 55 in data[1] and so on. then i can use these to carry out some calculations for the answer.
in the readGeo
do - FileReader file = new FileReader("fileName.txt");
-
BufferedReader input = new BufferedReader(file);
-
String line = input.readLine();
-
and now you have the first line in the string line
in the readGeo
do - FileReader file = new FileReader("fileName.txt");
-
BufferedReader input = new BufferedReader(file);
-
String line = input.readLine();
-
and now you have the first line in the string line
Would I have to do some sort of loop until all of the lines are read in?
Would I have to do some sort of loop until all of the lines are read in?
Yes. You would need a while loop for it.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Wendy S |
last post by:
We've been provided a Java app to use for a homework assignment on
databases. It's my own fault for writing inefficient queries, but it keeps
taking 100% of my CPU and it takes several minutes to...
|
by: lsprtt |
last post by:
I'm trying to create this program and I need some help
It includes using JAVA, XHTML and Servlet
Create a Web application for dynamic FAQs. The application should
obtain the information to...
|
by: Mondo Dynamo |
last post by:
A friend of mine is learning java as part of a Business Studies Degree
and is finding it very hard to get to grips with.
She has an assignment coming up soon and needs some help, she is
offering...
|
by: David Van D |
last post by:
Hi there,
A few weeks until I begin my journey towards a degree in Computer
Science at Canterbury University in New Zealand,
Anyway the course tutors are going to be teaching us JAVA wth bluej...
|
by: spawn |
last post by:
but I've been struggling with this for far too long and I'm about to
start beating my head against the wall.
My assignment seemed simple: create a program that will cacluate the
running total of...
|
by: spicster |
last post by:
I need help with finding an entire inventory value for a java assignment. This is what I have so far. I am new to Java and am struggling. In need of help, thanks
import...
|
by: DonE |
last post by:
Help me please. I am having problems with my homework assignment. We are to create a product class that hold the item number, the name of the product, the number of units in stock, and the price of...
|
by: s0suk3 |
last post by:
Hello, I was hoping to get some opinions on a subject. I've been
programming Python for almost two years now. Recently I learned Perl,
but frankly I'm not very comfortable with it. Now I want to...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |