title: Round Robin scheduling in java
body: <p>I'm trying to implement Round Robin scheduling algorithm. But the code I have done so far only consider the burst time. I also need to consider the arrival time of the process too. I have a time_chart array which I'm using to store the number of the process which is currently executing. But if no process is currently executing (that is if selected process has finished executing and next process has not arrived.), value 0 should be inserted into the time_chart array. </p>
  
  <p>I have stored burst time and arrival time in a 2D array as:</p>
  
  <pre><code>//proc[][0] is the AT array
  //proc[][1] is the BT array
  </code></pre>
  
  <p>and Time Quantum in variable q. Below is my code:</p>
  
  <pre><code>int time_chart[] = new int[total_time];
  int sel_proc = 1;
  int current_q = 0;
  
  for (int k = 0; k &lt; total_time; k++) {
  
      //Assign selected process to current time in the Chart
      time_chart[k] = sel_proc;
  
      //Decrement Remaining Time of selected process by 1 since it has been assigned the CPU for 1 unit of time
      proc[sel_proc - 1][1]--;
  
      //Updating value of sel_proc for next iteration
      current_q++;
  
      if (current_q == q || proc[sel_proc - 1][1] == 0)//If Time slice has expired or the current process has completed execution
      {
          current_q = 0;
          //This will select the next valid value for sel_proc
          for (int j = 1; j &lt;= n; j++) {
              sel_proc++;
              if (sel_proc == (n + 1)) {
                  sel_proc = 1;
              }
              if (proc[sel_proc - 1][1] != 0) {
                  break;
              }
          }
      }
  }
  
  // print timeline for testing
  for (i = 0; i &lt; total_time; i++) {
  System.out.println("Time " + i + ": " + time_chart[i]);
  }
  </code></pre>
  
  <p>currently it will select the next process even though it has not arrived yet. Therefore, I need to check if the next process has arrived or not. I tried using <code>proc[sel_proc][0] &lt;= k</code> to check this but it didn't seem to work. By that I mean I didn't get any output. I can't think of another way to check if the next process has arrived or not. How can I check this and put value 0 into the array if the next process has not arrived? </p>