Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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) { QueuemyQueue = 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started