Program sangat sederhana mencari nilai Average Waiting Time (AWT) dengan memakai bahasa Pascal, dengan menggunakan algoritma penjadwalan Come First Serve(FCFS) dan Short Job First (SJF) :
Program averagewaitingtimr;
uses wincrt;
type
time1=array[1...100] of integer;
wait1=array[1...100] of integer;
var
ulang:char;
pilih:byte;
n:integer;
procedure FCFS;
var
waktu:time1;
wait:wait1;
i,jumlah,sum:integer;
awt:real;
begin
clrscr;
writeln('**********************************************');
writeln('First Come First Served (FCFS)');
writeln('**********************************************');
write('Jumlah proses :');readln(n);
jumlah:=0;
sum:=0;
wait[1]:=0;
for:i=1 to n do
begin
write('Masukkan lama proses ke-',i,' :');readln(waktu[i]);
jumlah:=wait[i];
wait[i+1]=jumlah+waktu[i];
sum:=sum+wait[i];
end;
gotoxy(1,5+n);
writeln('******************************************************');
witeln('Proses |Working Time| Waiting Time(WT)');
writeln('******************************************************');
for i:=1 to n do
begin
gotoxy(1,(7+n)+i);write("|");
gotoxy(11,(7+n)+i);write("|");
gotoxy(24,(7+n)+i);write("|");
gotoxy(38,(7+n)+i);write("|");
end;
gotoxy(1,(7+n)+n)+1);
writeln('******************************************************');
for i:=1 to n do
begin
gotoxy(2,(7+n)+i);
write('Proses',i);
gotoxy(14,(7+n)+i);
write(waktu[i]);
gotoxy(26,(7+n)+i);
writeln(wait[i]);
end;
awt:=sum/n;
gotoxy(1,(9+n)+n);
writeln('Average Waiting Time (AWT) : ',sum,'/',n,':',awt:2:2);
readln;
end;
procedure SJF;
var
i,j,jumlah,sum,temp:integer;
awt:real;
waktu:time1;
wait:wait1;
begin
clscr;
writeln('***************************************');
writeln('Shortest Job First (SJF)');
writeln('***************************************');
write('Jumlah proses : ');readln(n);
jumlah:=0;
sum:=0;
wait[1]:=0;
temp:=0;
for i:=1 to n do
begin
write('Masukkan lama proses ke-',i,':');readln(waktu[i]);
end;
for i:=1 to (n-1) do
for j:=(i+1)to n do
begin
if waktu[j]<waktu[i] then
begin
temp:=waktu[i];
waktu[i]:=waktu[j];
waktu[j]:=temp;
end;
end;
gotoxy(1,5+n);
writeln('******************************************************');
writeln('Proses |Working Time| Waiting Time (WT)');
writeln('******************************************************');
for i:=1 to n do
begin
gotoxy(1,(7+n)+i);write("|");
gotoxy(11,(7+n)+i);write("|");
gotoxy(24,(7+n)+i);write("|");
gotoxy(38,(7+n)+i);write("|");
end;
gotoxy(1,(7+n)+n)+1);
writeln('******************************************************');
for i:=1 to n do
begin
gotoxy(2,(7+n)+i);write('Proses',i);
gotoxy(14,(7+n)+i);write(waktu[i]);
gotoxy(26,(7+n)+i);write(wait[i]);
jumlah:=wait[i];
wait[i+1]:=jumlah+waktu[i];
sum:=sum+wait[i];
end;
awt:=sum/n;
gotoxy(1,(9+n)+n);
writeln('Average Waiting Time (AWT) : ',sum,'/',n,' ; ',awt:2:2);
readln;
end;
procedure pilihan(pilih:byte);
begin
clrscr;
writeln('Pilihan :');
writeln('1. First Come First Served ');
writeln('2. Shortest Job First ');
writeln('3, Exit ');
write('Your Choice : ');readln(pilih);
case pilih of
1:fcfs;
2:sjf;
3:exit;
end;
end;
begin
ulang:='Y';
repeat
clrscr;
pilihan(pilih);
gotoxy(1,(10+n)+n);
write('Back to Main Menu (y/n) ?');
readln(ulang);
until upcase(ulang='N';
end