繁体   English   中英

如何使用布尔值创建mutator方法

[英]how to create a mutator methods with boolean

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

看来我们必须为此使用布尔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 ; 
}

根据您的输入,请在下面找到更新的程序:

  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();
    } 
  }

我也相信您想检查一下, myJobInQueue不为空,即if(!myJobInQueue.isEmpty() && myDuration > myPendingTime)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM