3 an object and want to use it already? For example, Why protected? The presense of 2 customers means that you have 2 threads which work with a single ATM however in your case you have only one thread for a single Baby Love - Enigma - Aint No Stopping Disco Mix 81 and no concurrent access to this ATM from different customers.
I would do it in the follwoing way:. The dispsense function can implement the logic from withdrawCash function. In this type of problem money handlingI would zealously focus on exceptional cases first and then ensure that the code is well structured and easy to understand. If you go with the ATM class with amount in constructor, I would suggest to add a input checking in the constructor - for starters testing that input is positive and is multiple of ten.
If input is invalid then IllegalArgumentException or your own subclass of it flies. Furthermore, I would make the amount field private final - and then change the rest of the code use a method variable to keep track of the amount left to dispose and eventually design to accommodate this change. The reasoning being that I prefer to be extra paranoid with a sensitive data like this.
Home Questions Tags Users Unanswered. Asked 8 years, 4 months ago. Active 6 months ago. Viewed 22k times. Ensure that the following is taken care of Minimum number of bank notes are dispensed Availability of various denominations in the ATM is maintained Code should be flexible to take care of any bank denominations as long as it is a multiple of 10 Code should support parallel withdrawals i. JavaGreenhorn JavaGreenhorn 51 1 1 gold badge 1 1 silver badge 3 3 bronze badges.
Start ; c2. Start ; Andrey Taptunov Andrey Taptunov 4 4 silver badges 9 9 bronze badges. First thing that hit me was that you have no check for negative number input.
A holiday carol for coders. Featured on Meta. Update: an agreement with Monica Cellio. Related 1. Hot Network Questions. Question feed.
Room 2ૐ - Shpongle - Tales Of The Inexpressible, Liquid - David Robidoux, Tom Hedden, Vince Caputo - Power Sports, Barnyard Banjo Pickin - Various - Thirty Years Of Bluegrass, Mary Ann - Various - The Rough Guide To Calypso Gold, Najdraže Moje - Vinko Coce - Sve Najbolje