الموضوع: شرح
عرض مشاركة واحدة
منتديات طلاب وطالبات جامعة الملك عبد العزيز منتديات طلاب وطالبات جامعة الملك عبد العزيز
  #1  
قديم 14-05-2012, 01:51 PM

R.R500 R.R500 غير متواجد حالياً

R.R500

 
تاريخ التسجيل: Sep 2008
التخصص: حاسبات
نوع الدراسة: إنتظام
المستوى: الثامن
الجنس: أنثى
المشاركات: 13
افتراضي شرح


import java.util.*;
import javax.swing.*;
public class CpuScheduling1
{
public static void main(String[ ]args)
{
int m=Integer.parseInt(JOptionPane.showInputDialog( " Menu\n[1]First- Come First-Served\n[2]Shortest Job First\n[3]Priority\n\nEnter Choice:"));
if (m==1) {FCFS();}
else if
(m==2) {SJF();}
else if
(m==3) {P();}
else
{JOptionPane.showMessageDialog(null,"Error Message","Error!",JOptionPane.ERROR_MESSAGE);}
}
public static void FCFS()
{
int bp[]=new int[5],wtp[] =new int[5],twt=0, awt,num;
String output1[]=new String[10];
for (num=0;num<=4;num++)
{
bp[num]=Integer.parseInt(JOptionPane.showInputDialog( "\nEnter Burst time for P"+(num+1)+" : "));
}
for (num=0;num<=4;num++)
{
if (num==0)
{
wtp[num]=0;
}
else
{
wtp[num]=wtp[ num-1]+bp[ num-1];
output1[num]="\nWaiting time for P"+(num+1)+" = "+wtp[num];
}

}
for (num=0;num<=4;num++)
{
twt=twt+wtp[ num];
}
awt=twt/5;
JOptionPane.showMessageDialog(null,output1,"FCFS", JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null,"\nAverage Waiting Time =" + awt,"FCFS",JOptionPane.INFORMATION_MESSAGE);
}
public static void SJF()
{
int bp[]=new int[5],wtp[] =new int[5],twt=0, awt,x,num, temp=0,p[ ]=new int[5];
boolean found=false;
for (num=0;num<=4;num++)
{
bp[num]=Integer.parseInt(JOptionPane.showInputDialog( "\nEnter Burst time for P"+(num+1)+" : "));
}
for (num=0;num<=4;num++)
{
p[num]=bp[num] ;
}
for (x=0;x<=3;x++)
{
for (num=0;num<=3;num++)
{
if (p[num]>p[num+1])
{
temp=p[num];
p[num]=p[num+ 1];
p[num+1]=temp;
}
}
}
for (num=0;num<=4;num++)
{
if (num==0)
{
for (x=0;x<=4;x++)
{
if (p[num]==bp[ x] && found==false)
{
wtp[num]=0;
JOptionPane.showMessageDialog(null, "\nWaiting time for P"+(x+1)+" = "+wtp[num]);
bp[x]=0;
found=true;
}
}
found=false;
}
else
{
for (x=0;x<=4;x++)
{
if (p[num]==bp[ x] && found==false)
{
wtp[num]=wtp[ num-1]+p[ num-1];
JOptionPane.showMessageDialog(null,"\nWaiting time for P"+(x+1)+" = "+wtp[num]);
bp[x]=0;
found=true;
}
}
found=false;
}
}
for (num=0;num<=4;num++)
{
twt=twt+wtp[ num];
}
JOptionPane.showMessageDialog(null,"\n\nAverage waiting time: "+(awt=twt/5) );

}
public static void P()
{
int bp[]=new int[5],wtp[] =new int[6],p[]=new int[5],sp[]= new int[5],twt=0, awt,num,x, temp=0;
boolean found=false;
for (num=0;num<=4;num++)
{
bp[num]=Integer.parseInt(JOptionPane.showInputDialog( "\nEnter Burst time for P"+(num+1)+" : "));
}
for (num=0;num<=4;num++)
{
p[num]=Integer.parseInt(JOptionPane.showInputDialog( "\nEnter Priority for P"+(num+1)+" : "));
}
for (num=0;num<=4;num++)
{
sp[num]=p[num] ;
}
for (x=0;x<=3;x++)
{
for (num=0;num<=3;num++)
{
if (sp[num]>sp[num+1])
{
temp=sp[num] ;
sp[num]=sp[num+ 1];
sp[num+1]=temp;
}
}
}
for (num=0;num<=4;num++)
{
if (num==0)
{
for (x=0;x<=4;x++)
{
if (sp[num]==p[ x] && found==false)
{
wtp[num]=0;
JOptionPane.showMessageDialog(null,"\nWaiting time for P"+(x+1)+" = "+wtp[num]);
temp=x;
p[x]=0;
found=true;
}
}
found=false;
}
else
{
for (x=0;x<=4;x++)
{
if (sp[num]==p[ x] && found==false)
{
wtp[num]=wtp[ num-1]+bp[ temp];
JOptionPane.showMessageDialog(null,"\nWaiting time for P"+(x+1)+" = "+wtp[num]);
temp=x;
p[x]=0;
found=true;
}
}
found=false;
}
}
for (num=0;num<=4;num++)
{
twt=twt+wtp[ num];
}
JOptionPane.showMessageDialog(null,"\n\nAverage waiting time: "+(awt=twt/5) );

}
}


((((ممكن مساعده في شرح هذا البرنامج)))
رد مع اقتباس