Results 1 to 2 of 2
 03152010, 03:51 AM #1Member
 Join Date
 Mar 2010
 Posts
 1
 Rep Power
 0
need help with Java coding for North West Corner algorithm
:confused:Hi,
I wrote a code to generate a table that reflects the supply of factory and demand of warehouse. here's the data
Factory Supply warehouse demand
Factory 1 100 Warehouse 1 150
Factory 2 200 Warehouse 2 180
Factory 3 300 Warehouse 3 270
I am suppose to write a program that would generate a table which looks like this
100 0 0
50 150 0
0 30 270
where the rows represent the supply and the columns represent the demand. Sum of row 1 equals the supply of factory 1 and so on. The sum of column 1 equals the demand of warehouse 1 and so on. I have attempted to write the program but it is not generating the table that I want. Please point out to me where the problem is and how it can be fix.
public class SD {
public static void main(String []args){
int []s={100,200,300};
int[]d={150,180,270};
System.out.println("s= "+s.length);
System.out.println("d= "+d.length);
int [][]calc=new int[s.length][d.length];
int sums=0;
int sumd=0;
for(int i=0;i<=s.length1;i++)
{ int totalsupply=s[i];
for(int j=0;j<=d.length1;j++)
{ int totaldemand=d[j];
if(s[i]<=d[j])
{ calc[i][j]=s[i];
calc[i+1][j]=d[j]s[i];
calc[0][1]=0;
calc[0][2]=0;
sums+=calc[i][j];
}
System.out.print(calc[i][j]+" ");
}
System.out.println("\n");
}
}
//output I get is this
//s= 3
//d= 3
//100 0 0
//50 80 200
//0 0 70
 03152010, 11:30 AM #2Senior Member
 Join Date
 Mar 2010
 Posts
 952
 Rep Power
 10
You have your array of arrays and nested loop set up properly. Now when you calculate your cells, you want to work on only the cell calc[i][j] during that iteration of the loop. in pseudocode:
Java Code:for (each factory) for (each warehouse) if (remaining demand for this factory can be filled from this warehouse) quantity q = remaining demand from this factory else quantity q = remaining supply in this warehouse enter q in this cell subtract q from this factory's demand subtract q from this warehouse's supply next warehouse next factory
Gary
Similar Threads

help with java coding
By helpisontheway in forum New To JavaReplies: 4Last Post: 11142009, 08:00 AM 
java coding
By zawad in forum Suggestions & FeedbackReplies: 1Last Post: 07072009, 02:55 PM 
Developer III  JAVA; North Texas area
By ScottSearch in forum Jobs OfferedReplies: 0Last Post: 09222008, 10:06 PM 
View Corner
By BogdanNb in forum SWT / JFaceReplies: 0Last Post: 07252008, 03:44 PM 
Java/Application Developers Needed  North Carolina
By brown2sl in forum Jobs OfferedReplies: 0Last Post: 03102008, 08:17 PM
Bookmarks