Question: This code generates random numbers and places them into a FIFO queue, then removes them and displays them in order. Modify this code so that

This code generates random numbers and places them into a FIFO queue, then removes them and displays them in order. Modify this code so that it also adds the random numbers to a PriorityQueue and then removes and displays them in order after the FIFO queue operations. How is the behavior different? Note this in the comments of the code.

/** * PQTest1 * * A simple program to demonstrate the use of priority queues * * @author Jeremy Morris * @version 20121011 */ import java.util.*; public class PQTest1 { public static void main(String[] args) { Queue myQueue = new LinkedList(); Scanner keyboard = new Scanner(System.in); System.out.print("Enter the number of random numbers you want to generate:"); int randNums = keyboard.nextInt(); while (randNums <=0 ) { System.out.println("ERROR - Must enter a positive number!"); System.out.print("Enter the number of random numbers you want to generate:"); randNums = keyboard.nextInt(); } System.out.println("Generating random numbers..."); int count=0; while (count                                            

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!