I'm having trouble trying to combine both these files into one file to run. Can you please
Fantastic news! We've Found the answer you've been seeking!
Question:
I'm having trouble trying to combine both these files into one file to run. Can you please help me combine these two files into one?
1. Process.java - object class
2. RRCpuAlgo.java - driver/main class
Process.java
public class Process { //initialize attributes private int arrival; private int initBurst; private int burst; private int complete=0; private int response=-1; //constructor public Process(int arrival, int burst){ this.arrival=arrival; this.initBurst=burst; this.burst=burst; } //Accessors public int getArrival(){ return arrival; } public int getInitBurst(){ return initBurst; } public int getBurst(){ return burst;} public int getResponse(){ return response; } public int getComplete(){return complete; } //go for process public int process(int quantum, int currentTime){ //if response has not been set, ie, check if the current process is the first one, set response time if(response<0) response = currentTime - arrival ; //check if burst is higher than quantum if(burst>quantum){ burst -= quantum;//reduce burst } else{ quantum = burst;//set quantum as burst burst=0;//set burst to zero } //set complete time when burst is 0, means the process is complete if(burst==0){ complete = currentTime + quantum; } return currentTime + quantum; //return next currentTime } }
RRCpuAlgo.java
import java.util.Scanner; public class RRCpuAlgo { public static void main(String[] args) { //initialize variables & object instances Scanner scan=new Scanner(System.in); int quantum; Process[] proc; //ask for process count System.out.println("Enter no of process: "); int procCount = scan.nextInt(); proc=new Process[procCount]; //loop, ask for arrival and burst time of each process for(int i=1; i<=procCount; i++ ){ System.out.println("Enter Process "+i+" arrival time: "); int arrival=scan.nextInt(); System.out.println("Enter Process "+i+" arrival time: "); int burst=scan.nextInt(); System.out.println(); proc[ (i-1) ]=new Process(arrival, burst); //create enew process and add it to array } //ask for quantum time; System.out.println("Enter time quantum: "); quantum=scan.nextInt(); scan.nextLine(); int currentTime=0;//initialize currentTime String gantt="0-"; // holder for gantt chart int id=0;//process index holder //do scheduling until all processes has no burst time while( hasBurst(proc) ){ if(id==procCount)//check if id is greater than procCount, means last process is the last process in process array id=0;//reset id to zero, means back to first process //check if arrivalTime is less than or equal to currentTime, and process has remaining burst time //means the process can start/proceed if(currentTime >= proc[id].getArrival() && proc[id].getBurst()>0){ currentTime = proc[id].process(quantum, currentTime); //set currentTIme by scheduling the current process gantt += "P"+(id+1)+"-"+currentTime+"-"; //add gantt chart output (process id and currentTime } id++; //increment id } //display output //average times holders double totalWaiting=0; double totalTurn=0; double totalResponse=0; //table header System.out.println("pid arrival burst complete turn waiting response"); //iterate all process for(int i=0; i0) return true; } return false; } }
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date: