Results 1 to 5 of 5
Thread: Calculating segment costs
- 11-16-2012, 01:01 PM #1
Member
- Join Date
- Nov 2012
- Location
- Brisbane, Australia
- Posts
- 8
- Rep Power
- 0
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
- 11-16-2012, 01:56 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
- 11-16-2012, 02:16 PM #3
Member
- Join Date
- Nov 2012
- Location
- Brisbane, Australia
- Posts
- 8
- Rep Power
- 0
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).
- 11-16-2012, 02:20 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
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.
- 11-16-2012, 02:32 PM #5
Member
- Join Date
- Nov 2012
- Location
- Brisbane, Australia
- Posts
- 8
- Rep Power
- 0
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
-
Object-Parameter passing costs
By NewEonOrchestra in forum New To JavaReplies: 1Last Post: 05-16-2012, 05:23 PM -
Significanlty lower development costs in high quality development
By espeo in forum Reviews / AdvertisingReplies: 5Last Post: 04-23-2010, 06:08 PM -
How to segment a part of an image when four cordinates are givven?
By LankanSniper in forum Java 2DReplies: 0Last Post: 12-13-2009, 07:44 AM -
Comparing costs method
By gwithey in forum New To JavaReplies: 2Last Post: 04-17-2009, 09:55 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks