/* This file contains many classes which implement "Jobable"
 * The main class is the same as the file "RandomJob", it also
 *  defines other classes. It is not so important to know every
 * detail of the jobs, only that they will work with your JobQueue
 * and Jobable interface.
 *
 * Place your main method in RandomJob in order to test JobQueue
 *
 * COP 3330: Fall 2006
 * Project 5
 */

import java.util.Random;

public class RandomJob implements Jobable {
    
    private static Random rnd = new Random();//Random object for generating random numbers
    protected int waitTime;//time to wait while job runs
    private int priority;//priority of the job
    private static final String JobName = "Random Job"; //title for this particular job
    
    public RandomJob(){
        //default constructor
        this.waitTime = rnd.nextInt(5) + 1;
        this.priority = rnd.nextInt(Jobable.MAXPriority);
    }
    
    public int getPriority(){
        return this.priority;
    }
    
    public String getJobName(){
        return JobName;
    }
    
    public void run(){
        System.out.println("this random job will take " + this.waitTime + " seconds.");
        try {
            Thread.currentThread().sleep(1000 * this.waitTime);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    
    public int compareTo(Jobable other){
    	//required by compareTo, compares based on priorities - can compare to anything else which
    	// is jobable, not just other RandomJobs
        if (other.getPriority() > this.priority ){
            return 1;
        }
        else if (other.getPriority() < this.priority){
            return -1;
        }
        return 0;
    }
    
    ///////////////////////////////////////////////////
    // class methods:
    
}

class LongJob extends RandomJob {
	
	private static final String JobName = "Long Job";
	
	public LongJob(){
		//creates a random job which is twice as long
		super();
		super.waitTime = super.waitTime * 2;
	}
	
	public String getJobName(){
		return LongJob.JobName;
	}
	
	//other methods inherited
}

class VirusCheckerJob extends LongJob {
	
	private static final String JobName = "Virus Checker"; 
	
	public void run(){
		//just changes what is printed during runtime
		System.out.println ("Checking your computer for viruses (not really)");
		super.run();	
	}
	
	public String getJobName(){
		return VirusCheckerJob.JobName;
	}
}
