Results 1 to 5 of 5
  1. #1
    sezzy is offline Member
    Join Date
    Nov 2012
    Location
    Brisbane, Australia
    Posts
    8
    Rep Power
    0

    Default Calculating segment costs

    I have been given a task of creating a 'traveling salesman' type programme in which I need to calculate costs.

    I need to create an array for six segments - A-B=2, A-C=3, A-D=1, B-C=4, B-D=2,C-D=3

    Now I'm not even sure that I've coded it correctly, I'm trying to ascertain the array...any help would be appreciated. I know I've incorrectly coded my 'answer', but I'm working on that now...I know I need to get it to loop, but I'm having a bit of a struggle.

    Any help is appreciated.

    import java.util.*;
    public class Travel2 {
    public static void main(String[] args) {

    int[] cost=new int[6];
    int index;

    cost [0] = 2;
    cost [1] = 3;
    cost [2] = 1;
    cost [3] = 4;
    cost [4] = 2;
    cost [5] = 3;

    /*Create a new scanner to read inputs*/
    Scanner reader = new Scanner (System.in);

    System.out.println("Enter ID of segment 0 of path: ");
    reader.nextInt();
    System.out.println("Enter ID of segment 1 of path: ");
    reader.nextInt();
    System.out.println("Enter ID of segment 2 of path: ");
    reader.nextInt();

    System.out.println("Total cost for this path: "+ (cost[0] + cost[1] + cost[2]));
    }

    }


    Cheers,

    Sez

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,372
    Blog Entries
    7
    Rep Power
    25

    Default Re: Calculating segment costs

    Quote Originally Posted by sezzy View Post
    I need to create an array for six segments - A-B=2, A-C=3, A-D=1, B-C=4, B-D=2,C-D=3
    How do we have to read this? Those are not just six linear equations are they?

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  3. #3
    sezzy is offline Member
    Join Date
    Nov 2012
    Location
    Brisbane, Australia
    Posts
    8
    Rep Power
    0

    Default Re: Calculating segment costs

    Sorry, I should have been clearer, I know the answer is right in front of me, I'm overthinking it.

    They correlate to segment numbers. I've been given a table with segment ID, Segment name and Travel cost, so A-B=$2million and so on.

    I need to calculate costs based on user input to four destinations (three inputs).

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,067
    Rep Power
    23

    Default Re: Calculating segment costs

    I think that's "distance" between all 4 places (A, B, C, D).
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    sezzy is offline Member
    Join Date
    Nov 2012
    Location
    Brisbane, Australia
    Posts
    8
    Rep Power
    0

    Default Re: Calculating segment costs

    Yes, so when all is said and done, the program needs to calculate A-D-C-B = 1+3+4=8

    I think I need to sleep on it and come back fresh in the morning, hopefully I'll be thinking clearer, at the moment I'm not even sure if I need to index it to get it to calculate as it should...

Similar Threads

  1. Object-Parameter passing costs
    By NewEonOrchestra in forum New To Java
    Replies: 1
    Last Post: 05-16-2012, 05:23 PM
  2. Replies: 5
    Last Post: 04-23-2010, 06:08 PM
  3. Replies: 0
    Last Post: 12-13-2009, 08:44 AM
  4. Comparing costs method
    By gwithey in forum New To Java
    Replies: 2
    Last Post: 04-17-2009, 09:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •