answersLogoWhite

0

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

class fcfs extends JFrame implements ActionListener

{

JButton jb[] = new JButton[3];

JTextField jt1[],jt2[];

JLabel jl[],jl1,jl2,jl3;

JPanel jp,jp1;

Container con;

int k,p;

String str[] = {"SUBMIT","RESET","EXIT"};

String str1[] = {"Process"," AT","ST","WT","FT","TAT","NTAT"};

public fcfs()

{

super("fcfs scheduling algoritham");

con = getContentPane();

k= Integer.parseInt(JOptionPane.showInputDialog("Enter number of

process"));

jl1 = new JLabel("Process");

jl2 = new JLabel("Arival Time");

jl3 = new JLabel("Service Time");

jl = new JLabel[k];

jt1 = new JTextField[k];

jt2 = new JTextField[k];

for(int i=0;i<k;i++)

{

jl[i] = new JLabel("process"+(i+1));

jt1[i] = new JTextField(10);

jt2[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(jt1[l]);

con.add(jt2[l]);

l++;

}

l=0;

for(int i=0;i<3;i++)

{

con.add(jb[l]);

jb[l].addActionListener(this);

l++;

}

}//end of constructor

public void actionPerformed(ActionEvent ae)

{

int FT[] = new int[k];

int WT[] = new int[k];

int TAT[] = new int[k];

float NTAT[] = 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[1])

{

setVisible(false);

fcfs window = new fcfs();

window.setSize(400,300);

window.setVisible(true);

window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

}//END ACTION PERFORMED

public static void main(String[] args)

{

fcfs window = new fcfs();

window.setSize(400,300);

window.setVisible(true);

window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}//end main

}//end class

User Avatar

Wiki User

13y ago

What else can I help you with?

Continue Learning about Engineering

What would be the effect using the FCFS scheme if the running process got stuck in an infinite CPU loop?

In FCFS the processes are in served by the order they arrive and each process will not start until the served process is finished, so if any of the processes got stuck in an infinite CPU loop the whole system will stop and hang.


What is the simplest scheduling algorithm?

The simplest scheduling algorithm is the First-Come, First-Served (FCFS) algorithm. In this approach, processes are executed in the order they arrive in the ready queue, without preemption. This means once a process starts executing, it runs to completion before the next process begins. While easy to implement, FCFS can lead to issues like the &quot;convoy effect,&quot; where shorter processes wait for longer ones, increasing overall waiting time.


What is queue discipline?

Queue discipline refers to the rules or policies that determine the order in which entities (such as customers, data packets, or tasks) are served in a queue. Common types of queue disciplines include First-Come, First-Served (FCFS), Last-Come, First-Served (LCFS), priority-based servicing, and round-robin. The choice of queue discipline can significantly impact the efficiency, fairness, and performance of a system, influencing wait times and resource utilization.


Source code for multilevel queue program in Java?

import java.io.*; import java.util.*; public class QueueImplement{ LinkedList&lt;Integer&gt; list; String str; int num; public static void main(String[] args){ QueueImplement q = new QueueImplement(); } public QueueImplement(){ try{ list = new LinkedList&lt;Integer&gt;(); InputStreamReader ir = new InputStreamReader(System.in); BufferedReader bf = new BufferedReader(ir); System.out.println("Enter number of elements : "); str = bf.readLine(); if((num = Integer.parseInt(str)) == 0){ System.out.println("You have entered either zero/null."); System.exit(0); } else{ System.out.println("Enter elements : "); for(int i = 0; i &lt; num; i++){ str = bf.readLine(); int n = Integer.parseInt(str); list.add(n); } } System.out.println("First element :" + list.removeFirst()); System.out.println("Last element :" + list.removeLast()); System.out.println("Rest elements in the list :"); while(!list.isEmpty()){ System.out.print(list.remove() + "\t"); } } catch(IOException e){ System.out.println(e.getMessage() + " is not a legal entry."); System.exit(0); } } }


Explai the nature of the various types queues in data structures?

The queue is a linear data structure where operations of insertion and deletion are performed at separate ends also known as front and rear. Queue is a FIFO structure that is first in first out. A circular queue is similar to the normal queue with the difference that queue is circular queue ; that is pointer rear can point to beginning of the queue when it reaches at the end of the queue. Advantage of this type of queue is that empty location let due to deletion of elements using front pointer can again be filled using rear pointer. A priority queue is a queue in which each element is inserted or deleted on the basis of their priority. A higher priority element is added first before any lower priority element. If in case priority of two element is same then they are added to the queue on FCFS basis (first come first serve). Mainly there are two kinds of priority queue: 1) Static priority queue 2) Dynamic priority queue A double ended queue (or deque ) is a queue where insertion and deletion can be performed at both end that is front pointer can be used for insertion (apart from its usual operation i.e. deletion) and rear pointer can be used for deletion (apart from its usual operation i.e. insertion)

Related Questions

Which os is used in FCFS?

FCFS, or First-Come, First-Served, is a scheduling algorithm commonly used in various operating systems, including Unix, Linux, and Windows. It is a simple, non-preemptive scheduling method where processes are executed in the order they arrive in the ready queue. While it is not the most efficient for time-sharing systems due to potential long wait times, it is easy to implement and can be found in many basic operating systems and environments.


Which is the oldest and simplest methods of odering?

The oldest and simplest method of ordering is the &quot;first-come, first-served&quot; (FCFS) approach. In this method, items or requests are processed in the order they arrive, with no prioritization or special treatment. This straightforward system is easy to understand and implement, making it ideal for basic queuing situations. However, it may not always be the most efficient for complex tasks or varying levels of urgency.


What would be the effect using the FCFS scheme if the running process got stuck in an infinite CPU loop?

In FCFS the processes are in served by the order they arrive and each process will not start until the served process is finished, so if any of the processes got stuck in an infinite CPU loop the whole system will stop and hang.


What are the disadvantages of FCFS scheduling?

in fcfs scheduling there is a shortcoming that is if any rocess of maximum brust time is first ome. and after that many short burst time process come. then smaller pocesses have to wait for a long time untill the max brust time process complete their execution. in case of shortest job first it applied the method to give shortest t\burst time job to processer first.


What are the advantages of FCFS scheduling?

First-Come, First-Served (FCFS) scheduling is simple and easy to implement, as it processes tasks in the order they arrive without preemption. This approach ensures fairness, as every process gets a chance to execute based on its arrival time. However, it can lead to inefficiencies, such as the &quot;convoy effect,&quot; where shorter tasks are delayed by longer ones. Despite this, its straightforward nature makes it suitable for simple systems where predictability is valued.


What is the simplest scheduling algorithm?

The simplest scheduling algorithm is the First-Come, First-Served (FCFS) algorithm. In this approach, processes are executed in the order they arrive in the ready queue, without preemption. This means once a process starts executing, it runs to completion before the next process begins. While easy to implement, FCFS can lead to issues like the &quot;convoy effect,&quot; where shorter processes wait for longer ones, increasing overall waiting time.


Briefly define FCFS scheduling?

FCFS is "First come, first served" Scheduling: Processes are given time on the CPU in the order that they arrive. eg: Process | Arrival Time (ns) | Burst Time (ns) P1 0 20 P2 0 10 P3 0 5 Scheduling Diagram for FCFS: | P1 | P2 | P3 | 0ns 20ns 30ns 35ns


Explain with an example first come first serve scheduling algorithm?

By far the simplest CPU-scheduling algorithm is the first-come, first-served (FCFS) scheduling algorithm. With this scheme, the process that requests the CPU first is allocated the CPU first. The implementation of the FCFS policy is easily managed with a FIFO queue. When a process enters the ready queue, its PCB is linked onto the tail of the queue. When the CPU is free, it is allocated to the process at the head of the queue. The running process is then removed from the queue. The code for FCFS scheduling is simple to write and understand. The average waiting time under the FCFS policy, however, is often quite long. Consider the following set of processes that arrive at time 0, with the length of the CPU-burst time given in milliseconds:


What relation holds between priority and first come first serve algorithm?

In scheduling algorithms, the priority method assigns tasks based on their importance, while the First-Come, First-Serve (FCFS) algorithm processes tasks in the order they arrive, regardless of priority. This means that in FCFS, a lower-priority task can delay a higher-priority one if it arrives first. Consequently, the two algorithms can lead to different performance outcomes, particularly in terms of response time and overall system efficiency. In contrast, priority scheduling aims to minimize wait times for high-priority tasks, potentially at the cost of lower-priority ones.


What do you understand by queue Discipline?

IN QUEueing theory,it is like how we serve people in waiting line --- 1.fcfs 2.round robin 3.sjf 4. siro 5.fifo


What kind of data structure is required to implement the round robin scheduling policy?

The circular queue data structure is required to implement the round robin scheduling policy. Round robin is similar to FCFS scheduling.


Comparison of FCFS SJF round robin algos?

FCFS = First Come First Serve SJF = Shortest Job First Round Robin = Skip from one job to the next giving each job an equal amount of processing time. (up to you or given) In an example: You have 4 jobs ahead of you. JobC, JobA, JobB, JobD and they were handed in to you, in that order. JobA will take 2 hours to do, JobB will take 1 hour, JobC will take 5 hours, and JobD will take 9 hours. FCFS, basically would mean you finish JobC first, since it came to you first. Then when JobC was done, you would work on JobA and so on. SJF, you would finish JobB first, then JobA, then JobC and then JobD. Round Robin, you would work on JobC for 1 hour, then JobA for 1 hour, then JobB for 1 hour and then JobD for 1 hour, and repeat.