Question: use java Create a program that uses a priority queue to collect user name and user age from a system user and then displays those
use java
Create a program that uses a priority queue to collect user name and user age from a system user and then displays those values in ascending order (regardless of the order in which they are added).
import java.util.PriorityQueue;
public class MIKESQCOMPARATORMAIN
{
public static void main(String[] args)
{
MyComparator comparator = new MyComparator();
PriorityQueue
pQueue.offer(new Employee("AAA", 15000));
pQueue.offer(new Employee("BBB", 12000));
pQueue.offer(new Employee("CCC", 7500));
pQueue.offer(new Employee("DDD", 17500));
pQueue.offer(new Employee("EEE", 21500));
pQueue.offer(new Employee("FFF", 29000));
pQueue.offer(new Employee("GGG", 14300));
System.out.println(pQueue.poll());
System.out.println(pQueue.poll());
System.out.println(pQueue.poll());
System.out.println(pQueue.poll());
System.out.println(pQueue.poll());
System.out.println(pQueue.poll());
System.out.println(pQueue.poll());
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
