Jump to content

part 3 of assignment

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
deelicious

deelicious

    Newbie

  • Members
  • Pip
  • 4 posts
Hey guys i posted up some problem i was having with the 1st part of my assign a few days ago. Now im doing the last part of it and seem to have another problem i cant seem to be able to resolve. the assignment requires me to read some data from a file and from tht data calculate distances for each using the lat and long values provided. I have done all that but there is a prt tht wasnt wrking in my first function. I read my file and used the indices for the names of the towns like a user can input 2 meaning california for example now for me to print my like the name in string format i have no idea wer im getting it wrong. My code looks like this


 roads = new ArrayList<Road>();


 for (int j=0; j< roads.size(); j++)

    {

System.out.println("Road from " + roads.get(j).OriginS + " to " + roads.get(j).destS + " distance " + roads.get(j).distance + "km");

}  

for the variable destS and OriginS theyv bin all declared as normal strings in another class, road. I am not sure if only this code will be sufficient for someone to assist me, i could have posted the full code to you but i am scared someone in my class might do a search on this and finds my code and then copy and paste it in his work. If you require me to send the code please do provide me with your email address rather which i can then use.

And actually this is not only the problem i have i need to calculate the shortest distance for 2 given cities in which case to display the routes possible and then highlight shortest path. I have no idea how i can start that one and i cannot use backtracking also.

Thanx,

#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
Hi i'd like to help, and indeed the given code isn't sufficient so you can reach me at <email removed by myself>

As for the shortest route.. do you have like a whole map of routes which are connected to eachother or so? If that's the case, the first thing that comes up my mind is Dijkstra's algorithm used in routers to calculate the shortest path to the destination router.
http://upload.wikime...ijksta_Anim.gif

Edited by wim DC, 15 October 2010 - 07:10 AM.