Java Assignment


importjava.util.List/* Java programto implementround-robin scheduling algorithm */publicclassRoundRobin {int [] tempint [] tempWaitingTimeintcommand,k, tqint[][]dint jjvoidstart( ){for int i= zero i is greater. length i++)(intbt = d[i][1]if( bt &gt 0){if( bt &lt= tq){temp[i]= jj+btjj = temp[i]k += btbt -=bt}else{temp[i]= jj+tqjj = temp[i]bt -= tqk += tq}d[i][1]= bt}}if( k!= command)start()}privatevoid display(List&ltJob&gt job List) {float avg Turn AroundTime = 0float awt = 0int c =1System.out.println(&quot============================================&quot)System.out.println(&quotProcess ID | Turnaround time |Waiting time&quot)System.out.println(&quot============================================&quot)Object[] job = jobList.toArray()for (int i :temp) {Job job1 = (Job) job[c-1]System.out.println( &quot&quot + c + &quot | &quot + i +&quot |&quot+(i-job1.getCpuTime()))System.out.println(&quot&quot)avgTurnArroundTime+= iawt +=(i-job1.getCpuTime())c++}System.out.println(&quot===============================================&quot)System.out.println(&quotAvg waiting time = &quot + awt /temp=lengthsystemdotout print…………………………………………systemdotout printin( averageturn-aroundtimeis equal&quot Plus standardturningaround timeover temp dotlengthSystem.Outprint(—&quot)(Public. avoid runs(listing&lt&ltJob&gt job List, intquantum) {int count = jobList.size()d = newint[pcount][2]temp = new int[pcount]int count =0for(Job job:jobList){d[count][0] = countint m =job.getCpuTime()d[count][1] = mcommand +=mcount++}tq = quantumstart()display(jobList)}}AllocationMethod.javaimportjava.util.Collectionimport java.util.Queueimportjava.util.ArrayListimport java.util.Iteratorimportjava.util.ListpublicabstractclassAllocation Method {protectedList&ltJob&gt Jobsprotected Array List&ltJob&gtQueuepublic Allocation Method(List&ltJob&gt jobs){super()Jobs= jobs}publicabstract void run()}Task.javapublicjobclassprivatizedint id,submissiontime,centralprocessing time,CPU timeleftPrivatisestarting time= zero, ending duration=zeropublictimeforprocessing=zero, endingtimeis equalzeroPublicarrivalprocessing timeintPublicwaiting durationintPublicturningaround timeintPrivatejobfinishingeventdurationintprivatearrivalDuration int, CPU periodforprocessingPublic task(int id, submission duration int, CPUduration int, task completion evt)(This is. Id equal toidthis.submissiontimeequalsto timesubmissionthis.cpu duration= cpu duration this.CPU durationleft=CPU periodthis. evert= evert ( public task (int process id, intarrival duration, int cpu duration) (this.Processingidis equalto processing idif(timeleftforcpu&lt0)(end Time = systemevt.onFinish(this)}}publicint getId() {returnid}publicvoid setId(int id) { = id}public intgetSubmitTime() {return submit Time}public voidsetSubmitTime(int submit Time) {this.submitTime = submitTime}public int getCPUTime() {returnCPUTime}public void setCPUTime(int cPUTime)CPUTime = cPUTime}public int getCPUTimeLeft(){return CPUTimeLeft}public void set CPU Time Left(int cPUTimeLeft) {CPUTimeLeft = CPU Time Left}publicint get Start Time() {return start Time}publicvoid set Start Time (int start Time) {this. start Time = startTime}public int getEndTime() {returnend Time}public void set End Time (int end Time) {this.end Time = end Time}public int get Arrival Time(){return arrival Time}public void set ArrivalTime (int arrival Time) {this. arrival Time = arrivalTime}public int get Cpu Time() {return CPUduration}public void set Cpu Time (int cpu Time){this.CPU Time = CPU Time}public int get ProcessId() {return process Id}public void set ProcessId(int process Id) {this. process Id = processId}}JobFinishEvent.javapublic interfaceJobFinishEvent {public void onFinish(Job j)} Exceptionimport java.util.Array Listimportjava.util.Listimport java.util.Scannerpublic class qq{public static void main(String[] args) {Scanner sc = newScanner( sc1 = newScanner( sc2 = new Scanner( String allocation Strategyint quantum=20nameof the file= &quottxt.testing&quotstrategy for allocation isequal to FCFS// name of the file= sc.line next()if(args. the length)(Listing&ltJob&gt job List = new ArrayList&ltJob&gt()while ((sCurrent Line = Line()) !=null) {String a[] = sCurrent Line.s plit(&quot,&quot)intprocess Id = new Integer(a[0])int arrival Time = newInteger(a[1])int cpu Time = new Integer(a[2])Job job =new Job(process Id, arrival Time, cpu Time)job List.add(job)System.out.println (process Id+&quot &quot+ arrivalTime+&quot &quot + CPU Time)}if(&quotFCFS&quot.equalsIgnore Case (allocation Strategy)){First Come First Servedfirst Come First Served = new First Come First Served( jobList)first Come First Served. run (job List)}elseif(&quotSRT&quot. equals Ignore Case(allocationStrategy)){Shortest Remaining Time shortest Remaining Time =new Shortest Remaining Time(job List)shortest Remaining (job List)}else if(&quotRR&quot. equals IgnoreCase(allocation Strategy)){RoundRobin round Robin = newRoundRobin()round Robin. run (job List, quantum)}}catch(IO Exception e) {e. print Stack Trace()} finally{try{if (br != null) br. Close ()} catch(IO Exception ex) {ex. print Stack Trace ()}}JobFinish Event call back = new Job Finish Event() {@Overridepublicvoid on Finish(Job j) {}}}}


Tutorialpoint. Java- Tutorial.01.01.2015 Web: 05.10.2015.&lthttp://www.tuto