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 = new PriorityQueue(7, comparator);

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

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!