Jump to content

Java experts come here once


Rachha_Rachha

Recommended Posts

Please give me inputs to achieve below sorting logic by using comparator.

HashMap<String, Double> priceMap = {1044504144=2.99, 1044714260=15.99, 1042614005=559.99, 1041705834=139.99, 1040569574=74.99, 1018868750=11.99, 1012182945=9.99, 1016275930=23.99, 1043844296=2.99, 1041703106=19.99, 1041267899=3.99, 1045610202=9.99, 3252228=179.98}

HashMap<String, Integer> reviewsCountMap = {1044504144=300, 1044714260=600, 1042614005=500, 1041705834=800, 1040569574=900, 1018868750=750, 1012182945=500, 1016275930=100, 1043844296=400, 1041703106=700, 1041267899=400, 1045610202=800, 3252228=200}

Logic for product id display will follow:
a. product id with Highest price; followed by
b. product id with Least # of reviews; followed by
c. product id with 2nd highest price; followed by
d. product id with 2nd least # of reviews; and so on
e.In case of products having the same price, the product with the less amount of views should display first
f.In case of products having the same amount of reviews, the higher priced product should display first
g.In case of products having the same price and number of reviews, the product with the higher product ID # will display first

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...