《先来先服务算法与短作业优先.doc》由会员分享,可在线阅读,更多相关《先来先服务算法与短作业优先.doc(3页珍藏版)》请在三一办公上搜索。
1、package a3;public class FCFS int finishtime;int arivetime;int starttime;int zhouzhuan;float weightzhouzhuan;public void fun()int a=4,3,5,2,4;int d=0,1,2,3,4,;for(int i=0;i5;i+)arivetime=di;starttime=finishtime;finishtime+=ai;zhouzhuan=finishtime-arivetime;weightzhouzhuan=(float)zhouzhuan/ai;System.o
2、ut.println(到达时间:+arivetime+ +开始时间:+starttime+ +服务时间:+ai+ +完成时间:+finishtime+ +周转时间:+zhouzhuan+ +带全周转时间:+weightzhouzhuan);package a3;import java.util.Arrays;public class SJF int starttime;int arivetime;int zhouzhuan;int finishtime;int a=4,3,5,2,4;public int fun()int b=new int5;for(int i=1;i5;i+)bi-1=a
3、i;Arrays.sort(b);System.out.println();return b;public void fun1()int c=new int5;c=this.fun();finishtime=a0;int d=0,3,1,4,2;int zhouzhuan= finishtime-arivetime;float weightzhouzhuan=(float)zhouzhuan/a0;System.out.println(到达时间:+ arivetime+ +开始时间:+starttime+ +服务时间:+a0+ +完成时间:+finishtime+ +周转时间:+zhouzhu
4、an+ +带全周转时间:+weightzhouzhuan);for(int k=1;k5;k+)starttime=finishtime;arivetime=dk;finishtime+=ck;zhouzhuan=finishtime-arivetime;weightzhouzhuan=(float)zhouzhuan/ck;System.out.println(到达时间:+ arivetime+ +开始时间:+starttime+ +服务时间:+ck+ +完成时间:+finishtime+ +周转时间:+zhouzhuan+ +带全周转时间:+weightzhouzhuan);package
5、 a3;import java.util.Scanner;public class TEST public static void main(String args) /int d=0,1,2,3,4,;/System.out.println(*);/System.out.println(请显示各进程到达时间:);/for(int i=0;i5;i+)/System.out.print(di+ );/System.out.println();System.out.println(*);System.out.println(请选择调度算法(0-1):);待添加的隐藏文字内容3System.out
6、.println(0.先来先服务调度:);System.out.println(1.短进程优先调度:);System.out.println(*);Scanner scanner=new Scanner(System.in);int i=scanner.nextInt();switch(i)case 0:System.out.println(*);System.out.println(对作业先来先服务调度:);System.out.println(*);FCFS fs=new FCFS();fs.fun();break;case 1:System.out.println(*);System.out.println(短进程优先调度:);System.out.println(*);SJF sj=new SJF();sj.fun1();break;