Problem statement:Write a CashWithDrawal function from an ATM which, based on user  specified amount, dispenses bank notes. Ensure that the following is  taken care of:Minimum number of bank notes are dispensedAvailability of various denominations in the ATM is maintainedCode should support parallel withdrawals (i.e two or more customers  can withdraw money simultaneously).  Take care of exceptional  situations.public class ATMMachine {    private Map<Integer, Integer> notes;    public ATMMachine(Map<Integer, Integer> notesMap){        notes = notesMap;    }    private boolean isCorrectAmt(int amt){        return amt%10==0 ? true : false;    }    private synchronized void reduceBalance(int denomination, int noToReduce){        int amt = notes.get(denomination);        notes.remove(denomination);        notes.put(denomination, amt-noToReduce);    }    public synchronized Integer getATMBalance(){        int balance = 0;        for(Integer denominator: notes.keySet()){            balance = balance + (denominator * notes.get(denominator));        }        return balance;         }    public synchronized Map<Integer, Integer> withdrawAmt(int amt){        Map<Integer, Integer> returnedMap = new HashMap<Integer, Integer>();        if(!isCorrectAmt(amt)){            System.out.println(Please enter amount in multiple of 10);            return returnedMap;        }        //get sorted denominations        TreeSet<Integer> denominations = new TreeSet<Integer>(notes.keySet());        Iterator<Integer> iter = denominations.descendingIterator();        while(amt > 0 ){                        int denomination = iter.next();            int noOfNotes = amt< denomination ? 0 : amt/denomination;            returnedMap.put(denomination, noOfNotes);            amt = amt - (denomination * noOfNotes);            reduceBalance(denomination, noOfNotes);                     }               return returnedMap;         }    public static void main(String agrs[]){        Map<Integer, Integer> notesMap = new HashMap<Integer, Integer>();        notesMap.put(500, 10);        notesMap.put(100, 20);        notesMap.put(50, 50);        notesMap.put(10, 30);        ATMMachine atm = new ATMMachine(notesMap);        System.out.println(Current balance is :  + atm.getATMBalance());        System.out.println(withdraw amt 200 + atm.withdrawAmt(800));        System.out.println(balance after withdrawing  + atm.getATMBalance());        ATMUser user = new ATMUser(atm, 4000);        Thread userThread1 = new Thread(user);        Thread userThread2 = new Thread(user);        userThread1.start();        userThread2.start();    }}public class ATMUser implements Runnable {    ATMMachine atm;    int amtToWithdraw;    public ATMUser(ATMMachine atm, int amtToWithdraw){        this.atm = atm;        this.amtToWithdraw = amtToWithdraw;    }    @Override    public void run() {        System.out.println(Balance in ATM is  + atm.getATMBalance());        System.out.println(withdrawin  amt :  + amtToWithdraw);           System.out.println(withdrawn :  + atm.withdrawAmt(amtToWithdraw));        System.out.println(Balance after withdraw is :  + atm.getATMBalance());    }}
ATM problem using collections
java;multithreading;collections;finance