0

我被要求创建一个使用 Array List 实现作业队列的类。我们可以将作业和运行时添加到队列中。作业从 JobInQueue 列表中的队列前面运行,myPendingTime 被减去,完成的作业进入 Finishedjobs 列表。

看起来我们必须为此使用 boolean mutator 方法,但我不确定如何创建此方法。谁能告诉我该怎么做。

/**
  * runs the first job on the queue if there is enough time on the clock.
  */
public boolean runJob()
{
    boolean jobDone = runJob(); 
     if(myJobInQueue.isEmpty() && myDuration > myPendingTime){
       myDuration-= myPendingTime;
       myJobInQueue.remove(0);
       myFinishedJobs.add(myJobInQueue.get(0));
       System.out.println("The job runing is : "+ myJobInQueue.get(0));
       jobDone=true;
     }
    return jobDone ; 
}
4

1 回答 1

1

Based on your inputs, please find the updated program below:

  public void runJob(){
    boolean jobDone = false; 
    if(!myJobInQueue.isEmpty() && myDuration > myPendingTime){
         myDuration-= myPendingTime;
         myFinishedJobs.add(myJobInQueue.get(0));
         myJobInQueue.remove(0);
         System.out.println("The job runing is : "+ myJobInQueue.get(0));
        jobDone=true;
    }
    if(!jobDone ){
         runJob();
    } 
  }

Also I believe you want to check, myJobInQueue is not empty i.e. if(!myJobInQueue.isEmpty() && myDuration > myPendingTime).

于 2012-10-07T01:10:33.790 回答