// Job.cpp     Dave Reed      1/20/05
//
// Job class implementation
///////////////////////////////////////////////////////////////////////////////

#include "Job.h"

Job::Job(int id, int len)
// Assumes: id is unique, len >= 0
// Results: constructs a job object, initializes executedSoFar to 0
{
    jobID = id;
    jobLength = len;    
    timeRemaining = jobLength;
}

bool Job::read(istream & istr)
// Assumes: istr contains job data
// Returns: true if successfully read job data from istr, else false
{
    istr >> jobID >> jobLength;
    timeRemaining = jobLength;
    return istr;
}

int Job::getID() const
// Returns: ID number of the job
{
    return jobID;
}

int Job::getJobLength() const
// Returns: length of the job
{
    return jobLength;
}

int Job::getRemainingTime() const
// Returns: time remaining to be executed
{
    return timeRemaining;
}

JobStatus Job::execute()
// Assumes: job is not done yet (timeRemaining > 0)
// Returns: status (OK or DONE) after executing the job for a cycle
{
    timeRemaining--;

    if (timeRemaining <= 0) {
        return DONE;
    }
    else {
        return OK;
    }
}

