answersLogoWhite

0


Best Answer

import java.io.*;

import java.util.*;

public class QueueImplement{

LinkedList<Integer> list;

String str;

int num;

public static void main(String[] args){

QueueImplement q = new QueueImplement();

}

public QueueImplement(){

try{

list = new LinkedList<Integer>();

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

}

}

}

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

/*

* MLFQ.java

*

* Created on December 3, 2008, 4:13 PM

*

* To change this template, choose Tools | Template Manager

* and open the template in the editor.

*/ import java.util.*; //ArrayList,Collection,LinkedList,List,Queue

import javax.swing.*; /**

* @author Ahmed Zaki

*/

class Process {

private String id_ ; // id of each process

private int arrival_time_ ;

private int burst_time_ ;

public Process(){

}

} public class MLFQ {

/** Creates a new instance of MLFQ */

public MLFQ() {

}

public static int NumOfProcess = 0;

private LinkedList<Process> Q0 = new LinkedList(); //Ready Queue with Quantium = 8 unit

private LinkedList<Process> Q1 = new LinkedList(); //Queue 1 With RR Quanum = 16 unit

private LinkedList<Process> Q2 = new LinkedList(); //Queue 2 With FCFS Paiorty

private List Process = new ArrayList();

private int Average_turnaround_time = 0;

private int Maximum_turnaround_time = 0;

private int Average_wait_time = 0;

private int Maximum_wait_time = 0;

private int CPU_utilization = 0;

private int Throughput = 0; // number of jobs process per hours

private int processes = 0;

public void addProcess() {

if ( NumOfProcess < 2 ){

JOptionPane.showMessageDialog(null, "U Must Enter At least Two Process \n We Must Exit the program Now");

System.exit(0);

}else{

for(int i=0 ; i<=NumOfProcess; i++ ){

// process ID

String id = JOptionPane.showInputDialog("Enter The Process ID !!!");

// process Arrival Time

String arr_time = JOptionPane.showInputDialog("Enter The Process Arrival Time !!");

int p_arr_time = Integer.parseInt(arr_time);

// process Burst Time

String bur_time = JOptionPane.showInputDialog("Enter The Process Burst Time !!!");

int p_bur_time = Integer.parseInt(bur_time);

}

}

}

public void removeProcess() {

}

public void quantumExpired() {

//queue.remove(p);

//queue.add(p);

//blockedOnQuantumExpiration++;

} public void addProcessTrace(Process p) {

// TODO Auto-generated method stub

} public void addProcessTraces(Collection<Process> list) {

// TODO Auto-generated method stub

}

public void blockedOnIO(Process p) {

// TODO Auto-generated method stub

} public void blockedOnPageFault(Process p) {

// TODO Auto-generated method stub

} public void blockedOnSleep(Process p) {

// TODO Auto-generated method stub

} public Process getCurrentProcess() {

// TODO Auto-generated method stub

return null;

} public boolean hasAliveProcess() {

// TODO Auto-generated method stub

return false;

} public boolean hasRunnableProcess() {

// TODO Auto-generated method stub

return false;

} public void quantumExpired(Process p) {

// TODO Auto-generated method stub

} public void removeProcess(Process p) {

// TODO Auto-generated method stub

} public void report() {

// TODO Auto-generated method stub

} public void unblocked(Process p) {

// TODO Auto-generated method stub

}

public static void main(String[] args){

MLFQ MultiFeed = new MLFQ();

String input = JOptionPane.showInputDialog("Enter The Number Of Process Plz");

NumOfProcess = Integer.parseInt(input);

MultiFeed.addProcess();

while(true){

String [] operations= { "Simulate and View the result "," Quit "};

int choice_=JOptionPane.showOptionDialog(null,"Select Ur Choice","Choice Menu",JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE,null,operations,operations[0]);

switch(choice_){

case 0:

MultiFeed.addProcess();

JOptionPane.showMessageDialog(null, " Please Wait While Compress Complete ... ");

break;

case 1:

JOptionPane.showMessageDialog(null, " Bye Bye ");

System.exit( 0 );

}

} } } /*

* MLFQ.java

*

* Created on December 3, 2008, 4:13 PM

*

* To change this template, choose Tools | Template Manager

* and open the template in the editor.

*/ import java.util.*; //ArrayList,Collection,LinkedList,List,Queue

import javax.swing.*; /**

* @author Ahmed Zaki

*/

class Process {

private String id_ ; // id of each process

private int arrival_time_ ;

private int burst_time_ ;

public Process(){

}

} public class MLFQ {

/** Creates a new instance of MLFQ */

public MLFQ() {

}

public static int NumOfProcess = 0;

private LinkedList<Process> Q0 = new LinkedList(); //Ready Queue with Quantium = 8 unit

private LinkedList<Process> Q1 = new LinkedList(); //Queue 1 With RR Quanum = 16 unit

private LinkedList<Process> Q2 = new LinkedList(); //Queue 2 With FCFS Paiorty

private List Process = new ArrayList();

private int Average_turnaround_time = 0;

private int Maximum_turnaround_time = 0;

private int Average_wait_time = 0;

private int Maximum_wait_time = 0;

private int CPU_utilization = 0;

private int Throughput = 0; // number of jobs process per hours

private int processes = 0;

public void addProcess() {

if ( NumOfProcess < 2 ){

JOptionPane.showMessageDialog(null, "U Must Enter At least Two Process \n We Must Exit the program Now");

System.exit(0);

}else{

for(int i=0 ; i<=NumOfProcess; i++ ){

// process ID

String id = JOptionPane.showInputDialog("Enter The Process ID !!!");

// process Arrival Time

String arr_time = JOptionPane.showInputDialog("Enter The Process Arrival Time !!");

int p_arr_time = Integer.parseInt(arr_time);

// process Burst Time

String bur_time = JOptionPane.showInputDialog("Enter The Process Burst Time !!!");

int p_bur_time = Integer.parseInt(bur_time);

}

}

}

public void removeProcess() {

}

public void quantumExpired() {

//queue.remove(p);

//queue.add(p);

//blockedOnQuantumExpiration++;

} public void addProcessTrace(Process p) {

// TODO Auto-generated method stub

} public void addProcessTraces(Collection<Process> list) {

// TODO Auto-generated method stub

}

public void blockedOnIO(Process p) {

// TODO Auto-generated method stub

} public void blockedOnPageFault(Process p) {

// TODO Auto-generated method stub

} public void blockedOnSleep(Process p) {

// TODO Auto-generated method stub

} public Process getCurrentProcess() {

// TODO Auto-generated method stub

return null;

} public boolean hasAliveProcess() {

// TODO Auto-generated method stub

return false;

} public boolean hasRunnableProcess() {

// TODO Auto-generated method stub

return false;

} public void quantumExpired(Process p) {

// TODO Auto-generated method stub

} public void removeProcess(Process p) {

// TODO Auto-generated method stub

} public void report() {

// TODO Auto-generated method stub

} public void unblocked(Process p) {

// TODO Auto-generated method stub

}

public static void main(String[] args){

MLFQ MultiFeed = new MLFQ();

String input = JOptionPane.showInputDialog("Enter The Number Of Process Plz");

NumOfProcess = Integer.parseInt(input);

MultiFeed.addProcess();

while(true){

String [] operations= { "Simulate and View the result "," Quit "};

int choice_=JOptionPane.showOptionDialog(null,"Select Ur Choice","Choice Menu",JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE,null,operations,operations[0]);

switch(choice_){

case 0:

MultiFeed.addProcess();

JOptionPane.showMessageDialog(null, " Please Wait While Compress Complete ... ");

break;

case 1:

JOptionPane.showMessageDialog(null, " Bye Bye ");

System.exit( 0 );

}

} } } /*

* MLFQ.java

*

* Created on December 3, 2008, 4:13 PM

*

* To change this template, choose Tools | Template Manager

* and open the template in the editor.

*/ import java.util.*; //ArrayList,Collection,LinkedList,List,Queue

import javax.swing.*; /**

* @author Ahmed Zaki

*/

class Process {

private String id_ ; // id of each process

private int arrival_time_ ;

private int burst_time_ ;

public Process(){

}

} public class MLFQ {

/** Creates a new instance of MLFQ */

public MLFQ() {

}

public static int NumOfProcess = 0;

private LinkedList<Process> Q0 = new LinkedList(); //Ready Queue with Quantium = 8 unit

private LinkedList<Process> Q1 = new LinkedList(); //Queue 1 With RR Quanum = 16 unit

private LinkedList<Process> Q2 = new LinkedList(); //Queue 2 With FCFS Paiorty

private List Process = new ArrayList();

private int Average_turnaround_time = 0;

private int Maximum_turnaround_time = 0;

private int Average_wait_time = 0;

private int Maximum_wait_time = 0;

private int CPU_utilization = 0;

private int Throughput = 0; // number of jobs process per hours

private int processes = 0;

public void addProcess() {

if ( NumOfProcess < 2 ){

JOptionPane.showMessageDialog(null, "U Must Enter At least Two Process \n We Must Exit the program Now");

System.exit(0);

}else{

for(int i=0 ; i<=NumOfProcess; i++ ){

// process ID

String id = JOptionPane.showInputDialog("Enter The Process ID !!!");

// process Arrival Time

String arr_time = JOptionPane.showInputDialog("Enter The Process Arrival Time !!");

int p_arr_time = Integer.parseInt(arr_time);

// process Burst Time

String bur_time = JOptionPane.showInputDialog("Enter The Process Burst Time !!!");

int p_bur_time = Integer.parseInt(bur_time);

}

}

}

public void removeProcess() {

}

public void quantumExpired() {

//queue.remove(p);

//queue.add(p);

//blockedOnQuantumExpiration++;

} public void addProcessTrace(Process p) {

// TODO Auto-generated method stub

} public void addProcessTraces(Collection<Process> list) {

// TODO Auto-generated method stub

}

public void blockedOnIO(Process p) {

// TODO Auto-generated method stub

} public void blockedOnPageFault(Process p) {

// TODO Auto-generated method stub

} public void blockedOnSleep(Process p) {

// TODO Auto-generated method stub

} public Process getCurrentProcess() {

// TODO Auto-generated method stub

return null;

} public boolean hasAliveProcess() {

// TODO Auto-generated method stub

return false;

} public boolean hasRunnableProcess() {

// TODO Auto-generated method stub

return false;

} public void quantumExpired(Process p) {

// TODO Auto-generated method stub

} public void removeProcess(Process p) {

// TODO Auto-generated method stub

} public void report() {

// TODO Auto-generated method stub

} public void unblocked(Process p) {

// TODO Auto-generated method stub

}

public static void main(String[] args){

MLFQ MultiFeed = new MLFQ();

String input = JOptionPane.showInputDialog("Enter The Number Of Process Plz");

NumOfProcess = Integer.parseInt(input);

MultiFeed.addProcess();

while(true){

String [] operations= { "Simulate and View the result "," Quit "};

int choice_=JOptionPane.showOptionDialog(null,"Select Ur Choice","Choice Menu",JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE,null,operations,operations[0]);

switch(choice_){

case 0:

MultiFeed.addProcess();

JOptionPane.showMessageDialog(null, " Please Wait While Compress Complete ... ");

break;

case 1:

JOptionPane.showMessageDialog(null, " Bye Bye ");

System.exit( 0 );

}

} } }

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Source code for multilevel queue program in Java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering
Related questions

Where can Java Queue be downloaded?

A 'queue' is a particular kind of data structure that Java is capable of working with. There are no products called "Java Queue" and is thus not something one can download.


How do you write a Java program to implement weighted queue using circular doubly linked list?

Add weights to the elements of the queue and use an algorithm to sort the queue every time an element is added.


In relation to Java what is a thread?

A Java Thread is a thread of execution in a Java Program. A Java Virtual Machine can have a single application running multiple threads, which is known as concurrency. Threads are what make the program run. Each thread has a different priority, and when the machine queue fills up, the threads are executed in the order of their priority.


It is not an error not to end a Java file name with the java extension?

If you want to compile a java program the name of that source code must end with extension .java


What is a Javacode?

If someone talks about "Java code," then they're are most likely referring to the source code of a Java program.


Why cant someone hack a Java program if they know the Java programming language?

Knowing Java does not allow you to hack a Java program because the source code is not available to hackers. Also, a program interprets the bit-code before you see it, so even with a decompiler, hacking the program will not be possible.


What do you get when you compile a java program?

The java interpreter or JVM (Java Virtual Machine) is not able to execute the java source code for a program. The java source code first needs to be compiled into bytecode that can be processed by JVM. Producing bytecode make the program platform independent as each platform has its own JVM. It is also possible to directly write bytecode, bypassing the need to compile, but that would be tedious job and also not good for security purpose as the compiler checks for various errors in a program.


Difference between a java complier and the Java JIT?

A java compiler takes Java source code and turns it into Java bytecode, which can then be run by the java virtual machine.Using JIT means that the java code will be compiled and executed at the time that you run the program, which will slow down the program because it has to compile the code at the same time that it runs.


How do you extract the java source code of a java based open source software?

If the software is open source then generally they will provide the code in a separate link. I don't think it is possible to reverse-engineer the code of a program.


Why 2 files in java program?

There are programming languages in which the source file is read and interpreted directly, but those are usually slower than when the program is compiled, to an EXE, or as in Java, for a virtual machine.


What are tools or software that are needed to editcompile and run to java?

To edit Java source code you can use any text editor. In order to compile a Java source file to Java bytecode you need the Java Development Kit (JDK). The program which does this is called "javac" and can produce .class files which can be used by the Java Runtime Environment (JRE) to execute.


What do you mean by multithread program in java?

A Program in Java that spawns multiple threads is called a multithreaded program in Java.