简体   繁体   中英

how to create a mutator methods with boolean

I was asked to create a class that implement a queue of jobs using Array List. We can add jobs and runtime to the queue. A job runs from the front of the queue in the JobInQueue list, myPendingTime gets subtracted and the completed job goes to the Finishedjobs list.

It looks like we have to use boolean mutator method for this but I am not sure how to create this method. could anyone tell me how to do this.

/**
  * 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 ; 
}

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 ie if(!myJobInQueue.isEmpty() && myDuration > myPendingTime) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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