Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Develop a GUI Java program to compare the performance of a process scheduling me

ID: 675426 • Letter: D

Question

Develop a GUI Java program to compare the performance of a process scheduling methods, FCFS (First Come First Served). Processes keep entering a computer system, operating system (Windows) receives the process information as follows:

Process number

Arrival time

Required processor time

Once a process receives the processor, it uses it until process completes. Measure and record the following parameters for each process:

Wait time = (start time) – (arrival time)

Turnaround time = (end time – arrival time)

List of all processes to be executed is recorded in a text file as:

Process ID (integer)

Arrival time

Execution time needed to complete the process

Your GUI interface should provide options for:

File

About

Exit

Process

Explanation / Answer

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class fcfs extends JFrame implements ActionListener
{
JButton jb[] = new JButton[3];
JTextField jtf1[],jtf2[];
JLabel jl[],jl1,jl2,jl3;
JPanel jp,jp1;
Container con;
int k,p,i;
String str[] = {"File","About","Exit"};
String str1[] = {"Process"," ATM","STM","WTM","FTM","TATM","NTATM"};


public fcfs()
   {
super("fcfs algoritham");
   con = getContentPane();

   k= Integer.parseInt(JOptionPane.showInputDialog("Enter required number of
process"));

   jl1 = new JLabel("Process");
   jl2 = new JLabel("Arival Time");
   jl3 = new JLabel("Service Time");

   jl = new JLabel[k];
jtf1 = new JTextField[k];
   jtf2 = new JTextField[k];


for(int i=0;i<k;i++)
       {
       jl[i] = new JLabel("process"+(i+1));
       jtf1[i] = new JTextField(10);
jtf2[i] = new JTextField(10);
   }

   for(int i=0;i<3;i++)
   {
       jb[i] = new JButton(str[i]);
   }

   con.setLayout(new GridLayout(k+2,3));
   con.add(jl1);
   con.add(jl2);
   con.add(jl3);

   int l=0;

   for(int i=0;i<k;i++)
       {
con.add(jl[l]);
           con.add(jtf1[l]);
           con.add(jtf2[l]);
           l++;
   }
   l=0;
   for(int i=0;i<3;i++)
       {
       con.add(jb[l]);
       jb[l].addActionListener(this);
       l++;
}
   }

   public void actionPerformed(ActionEvent ae)
   {
       int FTM[] = new int[k];
       int WTM[] = new int[k];
       int TATM[] = new int[k];
   float NTATM[] = new float[k];
       float sum=0;
float avg;
       JPanel main = new JPanel();
       main.setLayout(new BorderLayout());
       jp = new JPanel();
       jp1 = new JPanel();
       jp.setLayout(new GridLayout(k+1,7));
       jp1.setLayout(new FlowLayout());

       if(ae.getSource() == jb[2])
{
           System.exit(0);
   }
   else if(ae.getSource() == jb[0])
{
       FTM[0] = Integer.parseInt(jtf1[0].getText()) +
Integer.parseInt(jtf2[0].getText());

       for(int i=0;i<k;i++)
           {
           if(i==0)
               {
               WTM[i] = 0;
               }
           else
               {
               if(FTM[i-1] < Integer.parseInt(jtf1[i].getText()))
                   {
                   FTM[i] =
Integer.parseInt(jtf1[i].getText())+Integer.parseInt(jtf2[i].getText());
                   WT[i] = 0;
                   }
                   else
                   {
                       FTM[i] = FTM[i-1] + Integer.parseInt(jtf2[i].getText());
                       WTM[i] = FTM[i-1] - Integer.parseInt(jtf1[i].getText());
                   }

}
               TATM[i] = WTM[i]+Integer.parseInt(jtf2[i].getText());
               NTATM[i] = TATM[i]/(Integer.parseInt(jtf2[i].getText()));
               sum = sum+WTM[i];


           }
for (int i=0;i<7;i++ )
{
           jp.add(new JLabel(str1[i]));
}
           for (int i=0;i<k;i++)
           {
           jp.add(new JLabel("process"+(i+1)));
           jp.add(new JLabel(" "+Integer.parseInt(jtf1[i].getText())));
           jp.add(new JLabel(""+Integer.parseInt(jtf2[i].getText())));
           jp.add(new JLabel(""+WTM[i]));
           jp.add(new JLabel(""+FTM[i]));
           jp.add(new JLabel(""+TATM[i]));
       jp.add(new JLabel(""+NTATM[i]));


           }
           avg = sum/k;
           String str2 = "Average Waiting Time "+ avg;
jp1.add(new JLabel(str2));
           main.add(jp,BorderLayout.NORTH);
           main.add(jp1,BorderLayout.SOUTH);

JOptionPane.showMessageDialog(null,main,"output",JOptionPane.PLAIN_MESSAGE
);

}
       else if(ae.getSource() == jb[1])
       {
           setVisible(false);
           fcfs window = new fcfs();
           window.setSize(400,300);
           window.setVisible(true);
           window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

       }
   }

   public static void main(String[] args)
   {
fcfs window = new fcfs();
           window.setSize(500,400);
           window.setVisible(true);
           window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote