| | |
Keeping track of inserted coins.
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2007
Posts: 60
Reputation:
Solved Threads: 0
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.
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.
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.
![]() |
Similar Threads
- Is The Gov't Getting Rid Of Cash And Coins (Geeks' Lounge)
- memory management in wndows 2000 (Windows NT / 2000 / XP)
- Objects are not displaying in my program, also need to know how to work mouse clicks. (C++)
- Keeping track of the checkboxes selected acrros the page (PHP)
- First Attempt at Arrays (Java)
- Shooting at Virginia Tech (Geeks' Lounge)
- Keeping track of development knowledge (Computer Science)
- while loop in c++ help needed (C++)
- Objects (C)
Other Threads in the Java Forum
- Previous Thread: Bubble Sort in Linked List- Help Greatly Appreciated
- Next Thread: Illegal Start of Expression
Views: 795 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for Java
actuate android api apple applet application arguments array arrays automation balls binary bluetooth business c++ chat class classes client code codesnippet collections component database defaultmethod doctype dragging draw ebook eclipse error event exception file fractal froglogic game givemetehcodez graphics gui helpwithhomework hql html ide image input integer intersect invokingapacheantprogrammatically j2me java javaprojects jmf jni jpanel julia linux list loop looping map method methods mobile mysql netbeans newbie number numbers object oracle parameter php print problem program programming project recursion scanner screen server set size sms socket sort sql string sun swing swt tcp test threads time transfer tree udp windows






