// Path: thread/utilClasses/Process.java
// public class Process {
// 	public String jobName;
// 	public int arrivalTime;
// 	public int cpuTime;
// 	public int priority;
// 	public char symbol;
// 	
// 	public Process(){
// 		this.jobName = "";
// 		this.arrivalTime = 0;
// 		this.cpuTime = 0;
// 		this.priority = 1;
// 		this.symbol = '0';
// 	}
// 	
// 	public Process(String jobName, int arrivalTime, int cpuTime, char symbol){
// 		this.jobName = jobName;
// 		this.arrivalTime = arrivalTime;
// 		this.cpuTime = cpuTime;
// 		this.priority = 1;
// 		this.symbol = symbol;
// 	}
// 	
// 	public Process(String jobName, int arrivalTime, int cpuTime, int priority, char symbol){
// 		this.jobName = jobName;
// 		this.arrivalTime = arrivalTime;
// 		this.cpuTime = cpuTime;
// 		this.priority = priority;
// 		this.symbol = symbol;
// 	}
// 	
// }
// 
// Path: thread/utilClasses/Result.java
// public class Result {
// 	public String jobName;
// 	public char symbol;
// 	public float waitingTime;
// 	
// 	public Result() {
// 		this.jobName = "EMPTY";
// 		this.symbol = ' ';
// 		waitingTime = -1;
// 	}
// 	
// 	public Result(String jobName, char symbol){
// 		this.jobName = jobName;
// 		this.symbol = symbol;
// 		waitingTime = -1;
// 	}
// 	
// 	public Result(String jobName, char symbol, float waitingTime){
// 		this.jobName = jobName;
// 		this.symbol = symbol;
// 		this.waitingTime = waitingTime;
// 	}
// }


import java.util.Queue;
import thread.utilClasses.Process;
import thread.utilClasses.Result;
import java.util.LinkedList;

/************************************************************************************************
* Developer: Minhas Kamal(BSSE-0509, IIT, DU)													*
* Date: Sep-2014																				*
*************************************************************************************************/

package thread.priorityBased.premitive;



public class CPU {
	private final int CPU_CYCLE_TIME = 100;
	
	public int time = 0;
	public Queue<Process> waitingQueue = new LinkedList<Process>();
	public Queue<Result> result = new LinkedList<Result>();

	
	public Queue<Result> runProcess(Queue<Process> processes){

		while(!processes.isEmpty() || !waitingQueue.isEmpty()){
			
			//process starts
			while(!processes.isEmpty() && processes.element().arrivalTime<=time){
				waitingQueue.add(processes.peek());
				processes.remove();
				order(waitingQueue);
			}
			
			
			//run the program
			if(!waitingQueue.isEmpty()){
				waitingQueue.element().cpuTime -= CPU_CYCLE_TIME;
				waitingQueue.element().arrivalTime += CPU_CYCLE_TIME;
				
				
				if(waitingQueue.element().cpuTime<=0){	//process ends
					int waitingTime = time - waitingQueue.element().arrivalTime + CPU_CYCLE_TIME;
					result.add(new Result(waitingQueue.element().jobName, waitingQueue.element().symbol, waitingTime));
					

// Path: thread/utilClasses/Process.java
// public class Process {
// 	public String jobName;
// 	public int arrivalTime;
// 	public int cpuTime;
// 	public int priority;
// 	public char symbol;
// 	
// 	public Process(){
// 		this.jobName = "";
// 		this.arrivalTime = 0;
// 		this.cpuTime = 0;
// 		this.priority = 1;
// 		this.symbol = '0';
// 	}
// 	
// 	public Process(String jobName, int arrivalTime, int cpuTime, char symbol){
// 		this.jobName = jobName;
// 		this.arrivalTime = arrivalTime;
// 		this.cpuTime = cpuTime;
// 		this.priority = 1;
// 		this.symbol = symbol;
// 	}
// 	
// 	public Process(String jobName, int arrivalTime, int cpuTime, int priority, char symbol){
// 		this.jobName = jobName;
// 		this.arrivalTime = arrivalTime;
// 		this.cpuTime = cpuTime;
// 		this.priority = priority;
// 		this.symbol = symbol;
// 	}
// 	
// }
// 
// Path: thread/utilClasses/Result.java
// public class Result {
// 	public String jobName;
// 	public char symbol;
// 	public float waitingTime;
// 	
// 	public Result() {
// 		this.jobName = "EMPTY";
// 		this.symbol = ' ';
// 		waitingTime = -1;
// 	}
// 	
// 	public Result(String jobName, char symbol){
// 		this.jobName = jobName;
// 		this.symbol = symbol;
// 		waitingTime = -1;
// 	}
// 	
// 	public Result(String jobName, char symbol, float waitingTime){
// 		this.jobName = jobName;
// 		this.symbol = symbol;
// 		this.waitingTime = waitingTime;
// 	}
// }


// Path: thread/priorityBased/premitive/CPU.java
import java.util.Queue;
import thread.utilClasses.Process;
import thread.utilClasses.Result;
import java.util.LinkedList;

/************************************************************************************************
* Developer: Minhas Kamal(BSSE-0509, IIT, DU)													*
* Date: Sep-2014																				*
*************************************************************************************************/

package thread.priorityBased.premitive;



public class CPU {
	private final int CPU_CYCLE_TIME = 100;
	
	public int time = 0;
	public Queue<Process> waitingQueue = new LinkedList<Process>();
	public Queue<Result> result = new LinkedList<Result>();

	
	public Queue<Result> runProcess(Queue<Process> processes){

		while(!processes.isEmpty() || !waitingQueue.isEmpty()){
			
			//process starts
			while(!processes.isEmpty() && processes.element().arrivalTime<=time){
				waitingQueue.add(processes.peek());
				processes.remove();
				order(waitingQueue);
			}
			
			
			//run the program
			if(!waitingQueue.isEmpty()){
				waitingQueue.element().cpuTime -= CPU_CYCLE_TIME;
				waitingQueue.element().arrivalTime += CPU_CYCLE_TIME;
				
				
				if(waitingQueue.element().cpuTime<=0){	//process ends
					int waitingTime = time - waitingQueue.element().arrivalTime + CPU_CYCLE_TIME;
					result.add(new Result(waitingQueue.element().jobName, waitingQueue.element().symbol, waitingTime));
					

					waitingQueue.remove();
