Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: How can i write this in code?

  1. #1
    Junior Member
    Join Date
    Nov 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How can i write this in code?

    Trip Summary:
    Currently No Stops
    Total Tour Distance: 0.0 miles


    MENU
    A) Add a city onto tour
    I) Insert a city into the tour
    R) Remove a stop from the tour
    Q) Quit
    Selection: A

    Cities to Choose From:
    1) Austin, TX
    2) Baltimore, MD
    3) Boston, MA
    4) Chicago, IL
    5) Cleveland, OH
    6) Columbus, OH
    7) Dallas, TX
    8) Denver, CO
    9) Detroit, MI
    10) El Paso, TX
    Selection: 1

    Trip Summary:
    1. Austin, TX (30� 18' N, 97� 42' W)
    Total Tour Distance: 0.0 miles
    ---

    any advice or help is appreciated.


  2. #2
    Junior Member
    Join Date
    Nov 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How can i write this in code?

    can anyone please help me? or at least how to start or an outline? thank you so much in advance.

  3. #3
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: How can i write this in code?

    First, you'd need a list of all those cities you had, the distances between them, a simple map data structure (also known as a graph) that you can use to traverse which cities are more-or-less directly connected to each other.

    For information about the map data structure, see Wikipedia Graph (data structure).

    Once you have the cities in the graph correctly, you can traverse between any two points using Dijkstra's algorithm. If the order added is the order you want to visit them in, just run Dijkstra's algorithm multiple times between all the city pairs and sum up the mileage.

Similar Threads

  1. Writing in a file using Java
    By JavaPF in forum File Input/Output Tutorials
    Replies: 4
    Last Post: December 17th, 2011, 04:33 PM
  2. write object to sql db
    By wolfgar in forum JDBC & Databases
    Replies: 3
    Last Post: May 18th, 2010, 10:03 AM
  3. write text to a file help
    By wolfgar in forum File I/O & Other I/O Streams
    Replies: 8
    Last Post: November 24th, 2009, 08:36 AM
  4. How to write above a JPanel
    By bruno88 in forum AWT / Java Swing
    Replies: 4
    Last Post: June 23rd, 2009, 06:16 PM
  5. Someone please help me write a simple program!!!
    By ocean123 in forum Loops & Control Statements
    Replies: 3
    Last Post: June 14th, 2009, 09:46 PM