Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started