Question: import java.util. * ; public class Payment { private HashMap userToAmount; private PriorityQueue > topUsers; private static final int TOP _ USERS _ COUNT =
import java.util.;
public class Payment
private HashMap userToAmount;
private PriorityQueue topUsers;
private static final int TOPUSERSCOUNT ;
public Payment
userToAmount new HashMap;
topUsers new PriorityQueueComparatorcomparingIntMapEntry::getValue;
public TransactionSummary makePaymentint transactionId, int senderId int amount, TransactionType transactionType
if transactionType TransactionType.PM
userToAmount.putsenderId userToAmount.getOrDefaultsenderId amount;
Map.Entry currentUser new AbstractMap.SimpleEntrysenderId userToAmount.getsenderId;
if topUserssize TOPUSERSCOUNT
topUsers.addcurrentUser;
else if topUserspeekgetValue currentUser.getValue
topUsers.poll;
topUsers.addcurrentUser;
boolean isSenderEligibleForReward topUsers.containsnew AbstractMap.SimpleEntrysenderId userToAmount.getsenderId;
return new TransactionSummarytransactionId isSenderEligibleForReward;
public int getNumberOfTransactionsint senderId TransactionType transactionType
return userToAmount.getOrDefaultsenderId;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
