Question

In: Computer Science

In Java: Job class The Job implements the Comparable interface A Job object is instantiated with...

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.

Solutions

Expert Solution


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
       }
   }

}


Related Solutions

In Java: Job class The Job implements the Comparable interface A Job object is instantiated with...
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...
3.2. Unfortunately, you cannot modify the Rectangle class so that it implements the Comparable interface. The...
3.2. Unfortunately, you cannot modify the Rectangle class so that it implements the Comparable interface. The Rectangle class is part of the standard library, and you cannot modify library classes. Fortunately, there is a second sort method that you can use to sort a list of objects of any class, even if the class doesn't implement the Comparable interface. Comparator<T> comp = . . .; // for example, Comparator<Rectangle> comp = new RectangleComparator(); Collections.sort(list, comp); Comparator is an interface. Therefore,...
In java design and code a class named comparableTriangle that extends Triangle and implements Comparable. Implement...
In java design and code a class named comparableTriangle that extends Triangle and implements Comparable. Implement the compareTo method to compare the triangles on the basis of similarity. Draw the UML diagram for your classes. Write a Driver class (class which instantiates the comparableTriangle objects) to determine if two instances of ComparableTriangle objects are similar (sample output below). It should prompt the user to enter the 3 sides of each triangle and then display whether or not the are similar...
If a class A implements interface I1 and class C and D are derived from class...
If a class A implements interface I1 and class C and D are derived from class A, a variable of type I1 can be used to hold references of what type of objects? which one is correct 1. A, C, and D 2. A and D
In this class add Comparable interface. In the driver program create a few objects and In...
In this class add Comparable interface. In the driver program create a few objects and In the driver program create a few objects and compare them . then create a list of those objects and sort them .A Quadratic is bigger than another Quadratic if it opens faster package pack2; /** * This is a program for defining a quadratic equation * @author sonik */ public class Quadratic { public int coeffX2 = 0; public int coeffX = 0; public...
data structure class: a. syntax for generics b. comparable interface c.how do you implement interface answer...
data structure class: a. syntax for generics b. comparable interface c.how do you implement interface answer for all of them please. answer for all of them please
Define a class of queues that implements the interface QueueInterface, as defined in Listing 7-1 in...
Define a class of queues that implements the interface QueueInterface, as defined in Listing 7-1 in Chapter 7. Use an instance of the class ArrayList to contain a queues entries. Then write a driver/test program adequately demonstrates your new class. Note that you might have to handle exceptions thrown by methods of ArrayList. Deliverables: EmptyQueueException.java (given in Lab_7_StartUp folder) QueueInterface.java (given in Lab_7_StartUp folder) ArrayListQueue.java (need to create) Lab7.java (need to create) QueInterface: @author Frank M. Carrano @author Timothy M....
Suppose the interface and the class of stack already implemented, Write application program to ( java)...
Suppose the interface and the class of stack already implemented, Write application program to ( java) 1- insert 100 numbers to the stack                         2- Print the even numbers 3- Print the summation of the odd numbers
Write a Java program that implements a song database. The SongsDatabase class keeps tracks of song...
Write a Java program that implements a song database. The SongsDatabase class keeps tracks of song titles by classifying them according to genre (e.g., Pop, Rock, etc.). The class uses a HashMap to map a genre with a set of songs that belong to such a genre. The set of songs will be represented using a HashSet. Your driver output should sufficiently prove that your code properly implements the code below. public class SongsDatabase { private Map<String, Set<String>> genreMap =...
Write a program to have a Car class which is comparable. Make the Car class comparable...
Write a program to have a Car class which is comparable. Make the Car class comparable and use speed to compare cars. Write a method in Main class that finds the minimum of 4 things (generically). Create 4 cars and pass the cars to the minimum method and find the smallest car. Have a toString method for the Car class. The main program should be able to find out how many cars are created so far by calling a static...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT