Below is the question I need help with It need to be done in

Below is the question I need help with. It need to be done in Java. I need help making the priority queue part of the assignment, if you can add the GUI it will be helpful. You are to simulate a dispatcher using a priority queue system. New processes are to be entered using a GUI with priority included (numbering should be automatic). Processes are also to be terminated by GUI command. Context switches are to be by command with the cause of the switch being immaterial. Assume only one CPU. Priorities and numbers of processes can be kept small, just big enough to demonstrate the below listed functionality. You may pre-populate the queues initially from a data file. I am looking at the mechanism as you are NOT creating actual processes, just simulating them. Functionality to be provided by you:

1. Priority based Ready Queue(s).

2. Blocked list.

3. Output of complete system status after every context switch showing ready, blocked, and running processes.

Solution

import java.awt.Container;

import java.awt.Dimension;

import java.awt.FlowLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.util.PriorityQueue;

import java.util.Queue;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JTextArea;

import javax.swing.JTextField;

class dispatcher extends JFrame implements ActionListener {

static int processNo = 0;

static Process currentlyRunning;

static Queue<Process> readyQueue;

static Queue<Process> blockedQueue;

static JButton newProcess;

static JButton contextSwitch;

static JTextField priority;

static JTextArea Queues;

private static Process newProcess(int i, int i0, String running) {

throw new UnsupportedOperationException(\"Not supported yet.\");

}

dispatcher() {

Container cp = getContentPane();

cp.setLayout(new FlowLayout());

Queues = new JTextArea(5, 15);

Queues.setPreferredSize(new Dimension(500, 400));

cp.add(Queues);

cp.add(new JLabel(\"Priority\"));

priority = new JTextField(6);

newProcess = new JButton(\"Create Process\");

newProcess.addActionListener(this);

cp.add(priority);

cp.add(newProcess);

contextSwitch = new JButton(\"Context Switch\");

contextSwitch.addActionListener(this);

cp.add(contextSwitch);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setTitle(\"Dispatcher\");

setSize(600, 500);

setVisible(true);

}

public static void main(String args[]) {

dispatcher d = new dispatcher();

readyQueue = new PriorityQueue<>();

blockedQueue = new PriorityQueue<>();

Process p1 = newProcess(processNo++, 2, \"Running\");

Process p2 = newProcess(processNo++, 1, \"Blocked\");

Process p3 = newProcess(processNo++, 4, \"Ready\");

Process p4 = newProcess(processNo++, 3, \"Ready\");

Process p5 = newProcess(processNo++, 5, \"Ready\");

Process p6 = newProcess(processNo++, 8, \"Blocked\");

readyQueue.add(p3);

readyQueue.add(p4);

readyQueue.add(p5);

blockedQueue.add(p6);

blockedQueue.add(p2);

currentlyRunning = p1;

contextSwitch();

}

static void createProcess(int priority) {

readyQueue.add(newProcess(processNo++, priority, \"ready\"));

}

static void contextSwitch() {

String sb;

String currentState = null;

sb = \" \" + currentlyRunning

+ \"Currently Running Process\"+\"\ \"

+ \"Process No Priority Current State\ \"

+ currentlyRunning+processNo

+ \" \"+currentlyRunning+priority+currentState + \"\ \ \";

currentState = \"Blocked\";

blockedQueue.add(currentlyRunning);

currentlyRunning = readyQueue.poll();

currentState = \"Running\";

sb = sb + \"Ready Queue\ \" + \"Process No Priority Current State\ \";

for (Process p : readyQueue) {

sb = sb + p+processNo + \" \" + p+priority + \" \" + p+currentState

+ \"\ \ \";

}

sb = sb + \"\ Blocked Queue\ \" + \"Process No Priority Current State\ \";

for (Process p : blockedQueue) {

sb = \"\ \"

+ sb + p+processNo + \" \" + p+priority + \" \" + p+currentState;

Queues.setText(sb);

}

}

@Override

public void actionPerformed(ActionEvent e) {

if (e.getSource() == newProcess) {

System.out.print(\"process\");

int p = Integer.parseInt(priority.getText());

p = (p < 0) ? 2 : p;

createProcess(p);

} else{

System.out.print(\"context\");

contextSwitch();

}

}

Below is the question I need help with. It need to be done in Java. I need help making the priority queue part of the assignment, if you can add the GUI it will
Below is the question I need help with. It need to be done in Java. I need help making the priority queue part of the assignment, if you can add the GUI it will
Below is the question I need help with. It need to be done in Java. I need help making the priority queue part of the assignment, if you can add the GUI it will
Below is the question I need help with. It need to be done in Java. I need help making the priority queue part of the assignment, if you can add the GUI it will

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site