Hello,
I have got two arrays one called NB(number of memory blocks) and the other called NJ(number of Jobs). I want the NB arrays to search through the jobs and find a job that is <= to the block. So for example if i had:
Blocks
800
300
750
200
Jobs
200
720
900
500
The 200 jobs should look the the blocks list and fit memory that best fits it, in this case that would be block 200. And job 720 should look through the list and instead of going to block 800 it should go to memory 750 as it best fits it.
Here is my code below so far:
import java.util.*;
public class BestFit
{
public static final int NJ = 5;
public static final int NB = 5;
public static void main(String[] args) {
int [][] Jobs = new int [NJ][2];
int [][] block = new int [NB][2];
Random random = new Random();
for(int i=0; i<NJ; i++){
Jobs[i][0] = -1; // job has not been allocated
Jobs[i][1] = 100 + random.nextInt(900); //generate random number
}
for(int i=0; i<NB; i++){
block[i][0] = -1; // memory block has not been allocated
block[i][1] = 100 + random.nextInt(900);
}
for(int i=0; i<NJ;i++){
for(int j=0; j<NB; j++){
if(Jobs[i][1] <= block [j][1] && block[j][0] == -1 && Jobs[i][0] == -1){
block[j][0] = i;
Jobs[i][0] = j;
System.out.println("Job" + Jobs[i][1] + " in memory" + block[j][1]);
}
}
}
for(int i=0; i<NJ; i++){
System.out.println("Job [" + i +"][0] = " + Jobs[i][0]);
System.out.println("Job [" + i +"][1] = " + Jobs[i][1]);
}
for(int i=0; i<NB; i++){
System.out.println("block [" + i +"][0] = " + block[i][0]);
System.out.println("block [" + i +"][1] = " + block[i][1]);
}
}
}
All help appreciated.