In: Computer Science
In Java:
Job class
The Job implements the Comparable interface
A Job object is instantiated with three int variables, indicating the arrivalTime, the timeForTheJob, and the priority.
When the Job is created it is given the next sequential ID starting from 1. (You should use a static variable to keep track of where you are in ID assignment.)
There are also int variables for startTime, waitTime (in queue) and endTime for the Job.
The following methods are required:
getID,
set and get arrivalTime
set and get timeForJob
set and get prirority
set and get startTime
set and get endTime
get waitTime
When setting the startTime you should be able to calculate the waitTime
The compareTo interface is implemented based on priority, with priority 1 Jobs printed before priority two, etc.
I'm a tad stuck on the compareTo and creating a job object. If the answer doesn't have the job class implementing comparable, don't bother pasting it.
public class Job implements Comparable<Job>{
private int ID;
private int arrivalTime;
private int timeForJob;
private int priority;
private int startTime;
private int endTime;
private int waitTime;
public int getArrivalTime() {
return arrivalTime;
}
public void setArrivalTime(int arrivalTime) {
this.arrivalTime =
arrivalTime;
}
public int getTimeForJob() {
return timeForJob;
}
public void setTimeForJob(int timeForJob) {
this.timeForJob = timeForJob;
}
public int getPriority() {
return priority;
}
public void setPriority(int priority) {
this.priority = priority;
}
public int getStartTime() {
return startTime;
}
public void setStartTime(int startTime) {
this.startTime = startTime;
}
public int getEndTime() {
return endTime;
}
public void setEndTime(int endTime) {
this.endTime = endTime;
}
public int getID() {
return ID;
}
public int getWaitTime() {
return waitTime;
}
@Override
public int compareTo(Job job) {
if(this.getPriority()==job.getPriority()) {
return
0;//return 0 if both have same priority
}else if(this.getPriority() <
job.getPriority()) {
return
1;//return 1 if priority 1st have higher priority
}else {
return -1;
//return 1 if priority 1st have lower priority
}
}
}