I have a java class called MeterReading with two fields String MeterName and int MeterLevel.
Now, if the MeterLevel is between 0 and 3, that is Low, when between 3 and 6, Medium and from 6 above is High. How would I pass in that class MeterReading to a priority queue? Is this possible?
                        
You have to implements
Comparableinterface of your class. The trick is adding a method to get thelevelClass(LOW, MEDIUM, HIGH) that is used in thecompareTomethod.The implementation of
compareTocan be also the following if you need the opposite priority.To add a
MeterReadingto aPriorityQueueonly add it