I want to write a method for selecting a specific year (say 2009) from the Time array.
This would refer (8001) which is basically a key for year 2009.
In the FactTable I would like to add all the figures which represent quantity (the 1s). So it would show sales total for year 2009. Anyone have a clue how i can do this.
The Time array stores {timekey, year, month, week, day}
The FactTable stores {clientid, Vehicleid, branchid, timekey, quantity, profit}
int[][] Time = new int[][]
{{8001,2009,1,1,1},
{8002,2010,1,1,7},
{8003,2011,1,1,5},
{8004,2012,1,1,5}};
int[][] FactTable = new int [][]
{{1,125,20,8001,1,2000},
{2,126,40,8001,1,1500},
{3,127,50,8001,1,2500},
{4,128,10,8001,1,2500}};
int sum = 0;
int year = 8001;
for (int i = 0; i< FactTable.length-1; i++)
{
for (int j = 1; j < FactTable[i].length-1; j++)
{
year = year + FactTable + [0][4];
}
}
System.out.println (year);
i < FactTable.lengthand noti < FactTable.length - 1. The latter will skip the last entry. The latter would be correct if you made the condition<=instead of<. Secondly, please consider using a data structure to store this information instead of a multidimensional array. In other words write aFactclass which hasClientId,VehicleId, etc. properties. This will make your code much more readable, maintainable and less error-prone.