answersLogoWhite

0


Best Answer

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

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you do fcfs program in easy method using java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
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.


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)


What are the different types of queues?

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


Can you give a C programm about Shortest seek time first algorithm?

Suppose that a disk drive has 5000 cylinders, numbered 0 to 4999. The drive is currently serving a request at cylinder 143, and the previous request was at cylinder 125. The queue of pending requests, in FIFO order, is 86, 1470, 913, 1774, 948, 1509, 1022, 1750, 130 Starting from the current head position, what is the total distance (in cylinders) that the disk arm moves to satisfy all the pending requests, for each of the following disk- scheduling algorithms? A. FCFS B. SSTF C. SCAN D. LOOK E. C-SCAN F. C-LOOK Answer: A. The FCFS schedule is 143, 86, 1470, 913, 1774, 948, 1509, 1022, 1750, 130. The total seek distance is 7081. B. The SSTF schedule is 143, 130, 86, 913, 948, 1022, 1470, 1509, 1750, 1774. The total seek distance is 1745. C. The SCAN schedule is 143, 913, 948, 1022, 1470, 1509, 1750, 1774, 4999, 130, 86. The total seek distance is 9769. D. The LOOK schedule is 143, 913, 948, 1022, 1470, 1509, 1750, 1774, 130, 86. The total seek distance is 3319. E. The C-SCAN schedule is 143, 913, 948, 1022, 1470, 1509, 1750, 1774, 4999, 0, 86, 130. The total seek distance is 9985. F. The C-LOOK schedule is 143, 913, 948, 1022, 1470, 1509, 1750, 1774, 86, 130. The total seek distance is 3363.

Related questions

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.


Briefly define FCFS scheduling?

First-Come, First-Serve (FCFS) scheduling is one of the simplest scheduling algorithms in the realm of operating systems, and its implementation offers a straightforward approach to process management. In FCFS scheduling, processes are executed in the order they arrive in the ready queue, essentially adhering to a first-in, first-out (FIFO) strategy. The fundamental principle behind FCFS is straightforward: the first process to request the CPU gets executed first, and subsequent processes have to wait until the CPU is available again. The mechanism of FCFS scheduling is simple to understand and implement. When a process enters the system, it gets placed in the ready queue. The CPU scheduler picks the process at the head of the queue for execution and allocates the CPU to this process. The process continues to execute until it either finishes or gets blocked for I/O or some other reason, at which point the CPU is allocated to the next process in the ready queue. This cycle continues until all processes are executed. FCFS is non-preemptive, meaning once the CPU is allocated to a process, it retains control of the CPU until it completes its execution or gets blocked for some reason. This characteristic simplifies the scheduler design, making FCFS an attractive choice for simple systems or batch processing environments where jobs are more or less independent of each other. However, FCFS scheduling has its set of drawbacks. It can lead to the &quot;convoy effect,&quot; where short processes have to wait for a long process to complete, leading to suboptimal CPU utilization. The average waiting time under FCFS scheduling can be high if long processes arrive at the queue early. Moreover, FCFS does not prioritize processes based on their importance or urgency, which can be a significant limitation in scenarios where certain processes require immediate attention. Despite its limitations, the simplicity and ease of implementation of FCFS scheduling make it a viable choice in specific scenarios, especially in systems with minimal process management requirements or in batch processing environments. It serves as a foundation for understanding more complex scheduling algorithms and provides a clear illustration of how process scheduling works at a basic level. In a nutshell, FCFS scheduling is a fundamental, easy-to-implement scheduling algorithm that executes processes based on their arrival order, adhering to a non-preemptive, first-in, first-out strategy. While it may not be the most efficient or versatile scheduling algorithm, its simplicity makes it a useful stepping stone in the study of operating system scheduling algorithms, paving the way for understanding more advanced scheduling strategies.


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 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.


What is the difference between a priority queue and a circular queue?

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. 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).


Advantages and disadvantages of first come first serve scheduling?

First-come, first-served (FCFS) - sometimes first-in, first-served and first-come, first choice - is a service policy whereby the requests of customers or clients are attended to in the order that they arrived, without other biases or preferences. The policy can be employed when processing sales orders, in determining restaurant seating, on a taxi stand, etc. In Western society, it is the standard policy for the processing of most queues in which people wait for a service or two.


What are the relationships between priority and FCFS of CPU scheduling algorithms?

this is my doubt about the non-preemptive priority scheduling. i m doing bachelor of engineering in IT and this question in end semester exam. the question is as follows:Assume you have the following jobs to be executed with one processor, with the jobs arriving in the order listed here:Process Burst Time PriorityP1 80 5P2 20 1P3 10 3P4 20 2P5 50 4Suppose the system uses priority scheduling. Draw Gantt chart and calculate average waiting time for the processes.My doubt is:suppose if we were to use non-preemptive priority scheduling, the question says the jobs arriving in the order listed, so as per the order P1 will arrive first so it will get the CPU first and in non-preemptive once a job gets CPU it will not leave CPU till the process finishes, then as per the order P2 will come and same thing repeats.... so it acts like FCFS scheduling and priority is of no use here. But my lecturer says we have to follow the priority and P2 will come first, but the line the jobs arriving in the order listed is still not letting me agree with my lecturer. Can anyone help out?


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); } } }


What are non preemptive scheduling algorithms?

Strictly speaking, nonpreemptive scheduling is when the scheduler does not stop the process from running in order to switch it with a different process, but instead, it lets the process to complete and then schedules a different process depending on the a scheduling algorithm is uses.