It depends on what you expect from the system. If you go the most simplistic route, you assume that the machine has a limitless supply of change in all denominations. In that case, you only need to keep the total amount entered. To make change you just use division and mod functions to return the most efficient change combination.
Obviously, that isn't very realistic though. Real machines have a finite pool of coins of each denomination, in which case you would need separate totals for each, perhaps in a HashMap, in addition to the amount the user had entered. The returnChange() method would attempt to return the most efficient combination of denominations with division and mod, but if those coins were not available it would need to split down to the next combination of coins available to return the required amount.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Offline 6,761 posts
since May 2007