• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 349
  • Last Modified:

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.

THIS PROGRAMME CAN BE BASIC AND IN DOS FORM.

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

INDIANAPOLIS:IN:191520:-10440:339:367

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>
0
RamsTheDon
Asked:
RamsTheDon
  • 4
  • 3
  • 2
2 Solutions
 
abaloniaCommented:
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 TownsApp.java
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));
        }
        in.close();
    } catch (IOException e) {
    }
  }
}

// Town class, in Town.java
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
}
0
 
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;

to

 private ArrayList towns;

ArrayList is faster than Vector,but not thread safe and for other things check

http://www.codecomments.com/archive251-2005-6-517010.html
0
 
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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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.
0
 
abaloniaCommented:
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))) ;
0
 
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
thanks abalonia I was just about to correct that equation.

Thanks for correcting.

Bye.
0
 
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
0
 
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
I think you need to close the question again.

And please split the points.

Thank You.
0
 
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.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now