Route planning system in java

I need to write a short java programme that could form the core of  a route planning system. Users will enter names of towns and the programme will calculate distances and likely times.
The programme should:
1 Calculate speed between towns
2 Calculate time taken to travel btwn them
3 Use Kilometers
4 Should enable users to enter an itinerary showing distance travelled and time at which each town is reached.
5 The itinerary should include the arrival and departure time at each stop.
6 The programme will recognise journeys for which the total travelling time(excluding stops) exceeds a statutory maximum.
7 The programme will provide some means by which the user can select a particular town when there's more than one.


i've got a town.txt file  which has all town information (3310line).
It consists of a list of place names, each line (or record) consists of a name (all upper case letters), a two letter county code, the latitude and longitude of the place expressed in seconds with east latitudes being positive and the grid coordinates (east and north) expressed in kilometres. Each item of a record is separated by a colon.

For example


This means that Brisbane is in Bromley (BR), has a latitude of 191520 seconds north (53° 12’) and a longitude of 10440 seconds west (2° 54’), a grid east coordinate of 339 km and a grid north coordinate of 367 km.

The distance between place 1 and place 2 (in kilometres) can be calculated using the formula

Distance =(Math.pow((grid east 1 – grid east 2),2) + Math.pow((grid north 1 – grid north 2),2)) ;

How do i write a prgramme that accesses the information in the file and manipulate the information in the file to enable users to interact with the programme.
town.txt has got all the towns in the above format.

Please contact me if you need to ask any questions, re- my question

thanking you in advance

<changed by CS request by GranMod>
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Create a class to represent a Town and have its constructor accept a string formatted like one of the entries in the list of towns. In the constructor, split the string by colons to extract the individual values. Also write methods for accessing a Town's values and performing calculations. In the main class, read the towns file line-by-line using a BufferedReader. Create an instance of Town for each line and store it in a vector in the main class. When you receive user input, find the Towns you need in the vector and call the appropriate methods to perform operations on them.

This is a very rough outline of what I think you need. It's by no means complete, and I haven't tried it out:
// Main class, in
class TownsApp {
  private Vector towns;
  public static void main(String[] args) {
     try {
        BufferedReader in = new BufferedReader(new FileReader("towns.txt"));
        String str;
        while ((str = in.readLine()) != null) {
            towns.add(new Town(str));
    } catch (IOException e) {

// Town class, in
class Town {
  // Members
  private String name;
  private float lat;
  private float lon;
  private float e_coord;
  private float n_coord;
  private String county;

  // Constructors
  Town(String info) {
    String[] f = info.split(":");
    // Put in code for converting types.
  // Define accessors and mutators
  String getName() { return name; }
  String getCounty() { return county; }
  float getLat() { return lat; }
  float getLon() { return lon; }
  float getECoord() { return e_coord; }
  float getnNCoord() { return n_coord; }

  // Methods
  float getDistance(Town t) {
    // Computes distance to another town
    // Put implementation here

  // These two methods override the Object class's equals method. I think you need them for using the Vector class's search methods.
  boolean equals(Town t) {
   // Compare towns

  boolean equals(String n) {
    // Compare towns by name
  // Define additional methods

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
great job abalonia you are very clear in your approach. The program given above is very rough and simple implmentation.

And i have only one suggestion to make the program even lighter & effecient.

just change

>> private Vector towns;


 private ArrayList towns;

ArrayList is faster than Vector,but not thread safe and for other things check
RamsTheDonAuthor Commented:
Thank you very much abolonia , i'll try what you suggested after the hols, I have tried the programme and still coming with a few errors but will have a proper look as soon as i get enough time. Shivaspk i'll try to use the  private Arraylist towns; in place of >>private Vector towns. What do you think of the formula  Distance = &#8730;((grid east 1 – grid east 2)2 + (grid north 1 – grid north 2)2) to get distance between 2 towns, how do i incorporate it?

Thanks guys
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
 Distance =((grid east 1 – grid east 2)2 + (grid north 1 – grid north 2)2)

i think this must be the formula as it the distance formula, used to find distance between two potnts.

  Distance =(Math.pow((grid east 1 – grid east 2),2) + Math.pow((grid north 1 – grid north 2),2)) ;

just replace the variables in the above equation suitably.
Hmmm, well, I guess I could have gotten at least an assisted answer if I had replied sooner. Oh well, sorry for the delay in replying. I think you need a square root in the distance formula:
 Distance =Math.sqrt((Math.pow((grid east 1 – grid east 2),2) + Math.pow((grid north 1 – grid north 2),2))) ;
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
thanks abalonia I was just about to correct that equation.

Thanks for correcting.

RamsTheDonAuthor Commented:
abalonia thank you for the correction. The both of you(abolonia and shivaspk)have been very helpful  and i appreciate it.I'm still a novice and still finding my way around java and am easily confused about these codes.
I'm still cracking my head as i'm still getting numerous errors but i'm sure i'm on the right path with your assistance.

Thank you
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
I think you need to close the question again.

And please split the points.

Thank You.
RamsTheDonAuthor Commented:
Thanks shivaspk , i had requested community support to re-open the question because i realised i had not awarded any points to abalonia. This was a mistake on my part.
Once again thank you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.