public class EconomicModel {
public static void main(String[] args) {
int[] StarTime = new int[20];
int[] duration = new int[40];
int[] TotalDuration = new int[40];
int[] EndTime = new int[StarTime.length];
int[] relinqtime = new int[20];
int[] ResAllocRAM = {101,9,56,89,43,30,8,60,13,41,60, 20, 32,71,76,7,31,46,30,99 };
StarTime[0] = 0;
ExponentialDistribution exp = new ExponentialDistribution(4.0);
for(int j = 1; j < 20; j++){
StarTime[j] = (int)exp.sample() + 1+StarTime[j-1];
}
for(int k = 0; k < 20;k ++){
duration[k] = 20 + (int)(Math.random() * ((120 - 10) + 1));
}
for(int k = 0; k < 20; k++){
EndTime[k] = StarTime[k] + duration[k];
}
Random r = new Random();
for (int i=0; i<20; i++){
relinqtime[i] = r.nextInt((EndTime[i] - StarTime[i])+ StarTime[i] ) + StarTime[i];
}
for ( int j = 0; j<20; j++)
for(int k = StarTime[j]; k <= relinqtime[j]; k++){
TotalDuration[k]+= ResReqRAM[j];
}
}
}
I have arrays called StarTime
, relinqtime
, ResAllocRAM
and TotalDuration
. I want to assign values to the indexes of array TotalDuration
based on the other three arrays. Like if value of StarTime[1]
is 5, value of relinqtime[1]
is 8, value of ResAllocRAM[1]
is 9. I want that value TotalDuration[5]
,TotalDuration[6]
,TotalDuration[7]
should be the value of ResAllocRAM[1]
.
I tried the above code but it is giving exception bound error at line TotalDuration[k]+= ResReqRAM[j];
What should I do to map the values of these arrays and produce a new array as mentioned?
endTime
,startTime
, notEndTime
andStarTime
- uppercase letter at the beginning is reserved for types (classes, enums, interfaces).r.nextInt(EndTime[i])
is a shortcut forr.nextInt((EndTime[i] - StarTime[i])+ StarTime[i] )