944,000 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 947
  • Java RSS
Nov 16th, 2007
0

Keeping track of inserted coins.

Expand Post »
Hi I am creating a vending machine application that takes coins. It takes 5p, 10p 20p 50p £1 and £2 coins. Now I need to keep track of all the coins when inserted e.g. if I insert 2 pounds in 5p coins. When I chose to refund the money I need the machine to refund all the coins in random denominations but to the amount of £2. Or if I do buy something for say 25p, I need the machine to refund the change again in random denominations but to the correct change.
Similar Threads
Reputation Points: 14
Solved Threads: 0
Junior Poster in Training
Grub is offline Offline
60 posts
since Oct 2007
Nov 16th, 2007
0

Re: Keeping track of inserted coins.

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
Ezzaral is offline Offline
6,761 posts
since May 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Bubble Sort in Linked List- Help Greatly Appreciated
Next Thread in Java Forum Timeline: Illegal Start of Expression





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC