Java implementation for a little problem asking to output items in the order of their priority